From 9e5c3912b6cfce0348aa2d88d30a11fe5b410e9c Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 10 Apr 2018 18:22:16 -0400 Subject: move mock classes out of sample code (#471) --- .../Mock/Netcode/NetFieldBase.cs | 16 ++++++++++++++++ .../Mock/Netcode/NetInt.cs | 6 ++++++ .../Mock/Netcode/NetRef.cs | 6 ++++++ .../Mock/StardewValley/Item.cs | 18 ++++++++++++++++++ .../Mock/StardewValley/Object.cs | 6 ++++++ 5 files changed, 52 insertions(+) create mode 100644 src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetFieldBase.cs create mode 100644 src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetInt.cs create mode 100644 src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetRef.cs create mode 100644 src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Item.cs create mode 100644 src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Object.cs (limited to 'src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock') diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetFieldBase.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetFieldBase.cs new file mode 100644 index 00000000..1684229a --- /dev/null +++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetFieldBase.cs @@ -0,0 +1,16 @@ +// ReSharper disable CheckNamespace -- matches Stardew Valley's code +namespace Netcode +{ + /// A simplified version of Stardew Valley's Netcode.NetFieldBase for unit testing. + /// The type of the synchronised value. + /// The type of the current instance. + public class NetFieldBase where TSelf : NetFieldBase + { + /// The synchronised value. + public T Value { get; set; } + + /// Implicitly convert a net field to the its type. + /// The field to convert. + public static implicit operator T(NetFieldBase field) => field.Value; + } +} diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetInt.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetInt.cs new file mode 100644 index 00000000..b3abc467 --- /dev/null +++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetInt.cs @@ -0,0 +1,6 @@ +// ReSharper disable CheckNamespace -- matches Stardew Valley's code +namespace Netcode +{ + /// A simplified version of Stardew Valley's Netcode.NetInt for unit testing. + public class NetInt : NetFieldBase { } +} diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetRef.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetRef.cs new file mode 100644 index 00000000..714c4a8d --- /dev/null +++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetRef.cs @@ -0,0 +1,6 @@ +// ReSharper disable CheckNamespace -- matches Stardew Valley's code +namespace Netcode +{ + /// A simplified version of Stardew Valley's Netcode.NetRef for unit testing. + public class NetRef : NetFieldBase { } +} diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Item.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Item.cs new file mode 100644 index 00000000..88723a56 --- /dev/null +++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Item.cs @@ -0,0 +1,18 @@ +// ReSharper disable CheckNamespace, InconsistentNaming -- matches Stardew Valley's code +using Netcode; + +namespace StardewValley +{ + /// A simplified version of Stardew Valley's StardewValley.Item class for unit testing. + public class Item + { + /// A net int field with an equivalent non-net Category property. + public NetInt category { get; } = new NetInt { Value = 42 }; + + /// A net int field with no equivalent non-net property. + public NetInt type { get; } = new NetInt { Value = 42 }; + + /// A net reference field. + public NetRef refField { get; } = null; + } +} diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Object.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Object.cs new file mode 100644 index 00000000..498c38c1 --- /dev/null +++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Object.cs @@ -0,0 +1,6 @@ +// ReSharper disable CheckNamespace -- matches Stardew Valley's code +namespace StardewValley +{ + /// A simplified version of Stardew Valley's StardewValley.Object class for unit testing. + public class Object : Item { } +} -- cgit From 35c2e5968579ea578cf04e7550ab43bc5a4b8074 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 10 Apr 2018 18:22:34 -0400 Subject: expand analyzer unit tests (#471) --- .../Mock/Netcode/NetRef.cs | 2 +- .../Mock/StardewValley/Item.cs | 16 +++++++++++----- .../Mock/StardewValley/Object.cs | 10 ++++++++-- 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock') diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetRef.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetRef.cs index 714c4a8d..be2459cc 100644 --- a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetRef.cs +++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/Netcode/NetRef.cs @@ -2,5 +2,5 @@ namespace Netcode { /// A simplified version of Stardew Valley's Netcode.NetRef for unit testing. - public class NetRef : NetFieldBase { } + public class NetRef : NetFieldBase> where T : class { } } diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Item.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Item.cs index 88723a56..386767d7 100644 --- a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Item.cs +++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Item.cs @@ -7,12 +7,18 @@ namespace StardewValley public class Item { /// A net int field with an equivalent non-net Category property. - public NetInt category { get; } = new NetInt { Value = 42 }; + public readonly NetInt category = new NetInt { Value = 42 }; - /// A net int field with no equivalent non-net property. - public NetInt type { get; } = new NetInt { Value = 42 }; + /// A generic net int field with no equivalent non-net property. + public readonly NetInt netIntField = new NetInt { Value = 42 }; - /// A net reference field. - public NetRef refField { get; } = null; + /// A generic net ref field with no equivalent non-net property. + public readonly NetRef netRefField = new NetRef(); + + /// A generic net int property with no equivalent non-net property. + public NetInt netIntProperty = new NetInt { Value = 42 }; + + /// A generic net ref property with no equivalent non-net property. + public NetRef netRefProperty { get; } = new NetRef(); } } diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Object.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Object.cs index 498c38c1..3dd66a6d 100644 --- a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Object.cs +++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Object.cs @@ -1,6 +1,12 @@ -// ReSharper disable CheckNamespace -- matches Stardew Valley's code +// ReSharper disable CheckNamespace, InconsistentNaming -- matches Stardew Valley's code +using Netcode; + namespace StardewValley { /// A simplified version of Stardew Valley's StardewValley.Object class for unit testing. - public class Object : Item { } + public class Object : Item + { + /// A net int field with an equivalent non-net property. + public NetInt type = new NetInt { Value = 42 }; + } } -- cgit From 13f31e8b725e46ca8442a943a5675723d22b4fdc Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 10 Apr 2018 18:23:57 -0400 Subject: warn for fields which no longer work (#471) --- .../Mock/StardewValley/Farmer.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Farmer.cs (limited to 'src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock') diff --git a/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Farmer.cs b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Farmer.cs new file mode 100644 index 00000000..e0f0e30c --- /dev/null +++ b/src/SMAPI.ModBuildConfig.Analyzer.Tests/Mock/StardewValley/Farmer.cs @@ -0,0 +1,11 @@ +// ReSharper disable CheckNamespace, InconsistentNaming -- matches Stardew Valley's code +using System.Collections.Generic; + +namespace StardewValley +{ + /// A simplified version of Stardew Valley's StardewValley.Farmer class for unit testing. + internal class Farmer + { + public IDictionary friendships; + } +} -- cgit