public void Verify() { const string target = "I am Attribute, Hear me roar! #rawr!"; var configuration = new ConfigurationContainer(); configuration.Type <SimpleSubject>() .Member(x => x.Message) .Attribute(x => x == target); var support = new SerializationSupport(configuration); var expected = new SimpleSubject { Message = "Hello World!", Number = 6776 }; var content = support.Assert(expected, @"<?xml version=""1.0"" encoding=""utf-8""?><AttributeSpecificationTests-SimpleSubject xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ContentModel.Members;assembly=ExtendedXmlSerializer.Tests""><Message>Hello World!</Message><Number>6776</Number></AttributeSpecificationTests-SimpleSubject>"); Assert.Equal(expected.Message, content.Message); Assert.Equal(expected.Number, content.Number); expected.Message = target; var attributes = support.Assert(expected, @"<?xml version=""1.0"" encoding=""utf-8""?><AttributeSpecificationTests-SimpleSubject Message=""I am Attribute, Hear me roar! #rawr!"" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ContentModel.Members;assembly=ExtendedXmlSerializer.Tests""><Number>6776</Number></AttributeSpecificationTests-SimpleSubject>"); Assert.Equal(expected.Message, attributes.Message); Assert.Equal(expected.Number, attributes.Number); }
static void Main(string[] args) { SimpleSubject simpleSubject = new SimpleSubject(); SimpleObserver simpleObserver1 = new SimpleObserver(simpleSubject); SimpleObserver simpleObserver2 = new SimpleObserver(simpleSubject); SimpleObserver simpleObserver3 = new SimpleObserver(simpleSubject); simpleSubject.Value = 80; Console.ReadKey(); }
public void SimpleSubject_Checks() { var s = new SimpleSubject <int>(); var o1 = s.CreateObserver(); var o2 = s.CreateObserver(); Assert.AreSame(o1, o2); Assert.ThrowsException <ArgumentNullException>(() => s.Subscribe(null)); }
protected override void AssertValues(IExtObjectContainer objectContainer, object[] values) { object[] expected = CreateValues(); Assert.AreEqual(expected.Length, values.Length); SimpleSubject newObj = new SimpleSubject("new obj"); AssertItem <object>(objectContainer, expected[0], values[0], newObj); AssertItem(objectContainer, expected[1], values[1], 0xCACA); AssertItem <int?>(objectContainer, expected[2], values[2], 0xCACA); AssertItem(objectContainer, expected[3], values[3], newObj); }
public void SimpleSubject_Basics_OnNext() { var s = new SimpleSubject <int>(); var o1 = s.CreateObserver(); o1.OnNext(42); var s1 = new List <int>(); var d1 = s.Subscribe(x => s1.Add(x)); o1.OnNext(43); var s2 = new List <int>(); var d2 = s.Subscribe(x => s2.Add(x)); o1.OnNext(44); var s3 = new List <int>(); var d3 = s.Subscribe(x => s3.Add(x)); o1.OnNext(45); d1.Dispose(); o1.OnNext(46); d3.Dispose(); o1.OnNext(47); var s4 = new List <int>(); var d4 = s.Subscribe(x => s4.Add(x)); o1.OnNext(48); d2.Dispose(); d4.Dispose(); o1.OnNext(49); var s5 = new List <int>(); var d5 = s.Subscribe(x => s5.Add(x)); o1.OnNext(50); Assert.IsTrue(new[] { 43, 44, 45 }.SequenceEqual(s1)); Assert.IsTrue(new[] { 44, 45, 46, 47, 48 }.SequenceEqual(s2)); Assert.IsTrue(new[] { 45, 46 }.SequenceEqual(s3)); Assert.IsTrue(new[] { 48 }.SequenceEqual(s4)); Assert.IsTrue(new[] { 50 }.SequenceEqual(s5)); }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj.GetType() != GetType()) { return(false); } SimpleSubject rhs = (SimpleSubject)obj; return(rhs._name == _name); }
public void SimpleNonStringAsAttribute() { const string message = "Hello World! This is my unencrypted message!"; var identifier = new Guid("B496F7F5-58F8-41BF-AF18-117B8F3743BF"); var support = new SerializationSupport(new ConfigurationContainer().Type <SimpleSubject>().Member(x => x.Identifier).Attribute().Encrypt().Create()); var expected = new SimpleSubject { Identifier = identifier, Message = message }; var actual = support.Assert(expected, @"<?xml version=""1.0"" encoding=""utf-8""?><EncryptionExtensionTests-SimpleSubject Identifier=""YjQ5NmY3ZjUtNThmOC00MWJmLWFmMTgtMTE3YjhmMzc0M2Jm"" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ExtensionModel.Encryption;assembly=ExtendedXmlSerializer.Tests""><Message>Hello World! This is my unencrypted message!</Message></EncryptionExtensionTests-SimpleSubject>"); Assert.Equal(identifier, actual.Identifier); Assert.Equal(message, actual.Message); }
public void SimpleStringAsAttribute() { const string message = "Hello World! This is my encrypted message!"; var support = new SerializationSupport(new ConfigurationContainer().Emit(EmitBehaviors.Assigned) .Type <SimpleSubject>() .Member(x => x.Message).Attribute().Encrypt() .Create()); var expected = new SimpleSubject { Message = message }; var actual = support.Assert(expected, @"<?xml version=""1.0"" encoding=""utf-8""?><EncryptionExtensionTests-SimpleSubject Message=""SGVsbG8gV29ybGQhICBUaGlzIGlzIG15IGVuY3J5cHRlZCBtZXNzYWdlIQ=="" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ExtensionModel.Encryption;assembly=ExtendedXmlSerializer.Tests"" />"); Assert.Equal(message, actual.Message); }
public void BasicAttributes() { var serializer = new ConfigurationContainer() .Type <SimpleSubject>() .Member(x => x.Number, x => x.Attribute()) .Create(); var expected = new SimpleSubject { Message = "Hello World!", Number = 6776 }; var data = serializer.Serialize(expected); var actual = serializer.Deserialize <SimpleSubject>(data); Assert.Equal(expected.Message, actual.Message); Assert.Equal(expected.Number, actual.Number); }
public void SimpleSubject_Basics_DoubleDisposeIsFine() { var s = new SimpleSubject <int>(); var o1 = s.CreateObserver(); var d = s.Subscribe(_ => { Assert.Fail(); }); d.Dispose(); o1.OnNext(42); d.Dispose(); o1.OnNext(42); }
public void Subject1Test() { ISubject <int, string> xs = new SimpleSubject <int, string>(l => l.ToString().PadRight(l, '*')); var ys = xs.Monitor("Subject", 1); ys.Subscribe(); xs.OnNext(1); Thread.Sleep(1000); ys.OnNext(2); Thread.Sleep(1000); ys.OnNext(3); Thread.Sleep(100); GC.KeepAlive(ys); }
public void SimpleSubject_DisposedBehavior() { var s = new SimpleSubject <int>(); var d1 = s.Subscribe(); for (int i = 0; i < 2; i++) { s.Dispose(); Assert.ThrowsException <ObjectDisposedException>(() => s.OnNext(42)); Assert.ThrowsException <ObjectDisposedException>(() => s.OnError(new Exception())); Assert.ThrowsException <ObjectDisposedException>(() => s.OnCompleted()); d1.Dispose(); Assert.ThrowsException <ObjectDisposedException>(() => s.Subscribe()); } }
public void SubscriptionStateVisitor_Basics() { var state = new MockOperatorStateContainer(); var writerFactory = state.CreateWriter(); var readerFactory = state.CreateReader(); var xs = new SimpleSubject <int>(); var o = xs.CreateObserver(); var ys = new Take <int>(xs, 5); { var s1 = ys.Subscribe(Observer.Create <int>(_ => { }, _ => { }, () => { })); var v = new SubscriptionInitializeVisitor(s1); v.Subscribe(); v.Start(); o.OnNext(42); o.OnNext(43); var sv = new SubscriptionStateVisitor(s1); Assert.IsTrue(sv.HasStateChanged()); sv.SaveState(writerFactory); Assert.IsTrue(sv.HasStateChanged()); sv.OnStateSaved(); Assert.IsFalse(sv.HasStateChanged()); o.OnNext(44); o.OnNext(45); Assert.IsTrue(sv.HasStateChanged()); } { var done = false; var s2 = ys.Subscribe(Observer.Create <int>(_ => { }, _ => { }, () => { done = true; })); var sv = new SubscriptionStateVisitor(s2); sv.LoadState(readerFactory); var v = new SubscriptionInitializeVisitor(s2); v.Subscribe(); v.Start(); o.OnNext(46); Assert.IsFalse(done); o.OnNext(47); Assert.IsFalse(done); o.OnNext(48); Assert.IsTrue(done); } }