public void TestCopying() { var origNull = new AgentField(null); origNull.SetValue("One", 1); var copyNull = new AgentField("Foo"); // Different default! copyNull.SetValue(origNull); copyNull.GetValue().Should().Be("One"); copyNull.GetConfidence().Should().Be(1); copyNull.Reset(); copyNull.GetValue().Should().Be("Foo"); // The default should NOT be modified copyNull.GetConfidence().Should().Be(-1); var origFoo = new AgentField("Foo"); origFoo.SetValue("Two", 2); var copyFoo = new AgentField(null); // Different default! copyFoo.SetValue(origFoo); copyFoo.GetValue().Should().Be("Two"); copyFoo.GetConfidence().Should().Be(2); copyFoo.Reset(); copyFoo.GetValue().Should().BeNull(); // The default should NOT be modified copyFoo.GetConfidence().Should().Be(-1); }
public void ComparingUserAgents() { UserAgent baseAgent = new UserAgent("Something 2"); UserAgent agent0 = new UserAgent("Something 2"); UserAgent agent1 = new UserAgent("Something 1"); UserAgent agent2 = new UserAgent("Something 2"); UserAgent agent3 = new UserAgent("Something 2"); UserAgent agent4 = new UserAgent("Something 2"); var field0 = new AgentField("Foo"); field0.SetValue("One", 1); var field1 = new AgentField("Foo"); field1.SetValue("One", 1); var field2 = new AgentField("Foo"); // Same, different value field2.SetValue("Two", 1); var field3 = new AgentField("Foo"); // Same, different confidence field3.SetValue("One", 2); var field4 = new AgentField(null); // Same, different default field4.SetValue("One", 1); // We compare the base agent with 4 variations baseAgent.SetImmediateForTesting("Field", field0); agent0.SetImmediateForTesting("Field", field1); // Same agent1.SetImmediateForTesting("Field", field1); // Different useragent agent2.SetImmediateForTesting("Field", field2); // Different field value agent3.SetImmediateForTesting("Field", field3); // Different field confidence agent4.SetImmediateForTesting("Field", field4); // Different field default value // Check em baseAgent.Should().BeEquivalentTo(baseAgent); baseAgent.Should().BeEquivalentTo(agent0); agent0.Should().BeEquivalentTo(baseAgent); baseAgent.GetHashCode().Should().Be(agent0.GetHashCode()); Log.Info(baseAgent.ToString("Field")); baseAgent.Equals(agent2).Should().BeFalse(); baseAgent.Equals(agent3).Should().BeFalse(); baseAgent.Equals(agent4).Should().BeFalse(); agent1.Equals("String").Should().BeFalse(); "String".Equals(agent1).Should().BeFalse(); }