Esempio n. 1
0
        public DomainObjectGrainTests()
        {
            A.CallTo(() => store.WithSnapshotsAndEventSourcing(typeof(MyDomainObject), id, A <Func <MyDomainState, Task> > .Ignored, A <Func <Envelope <IEvent>, Task> > .Ignored))
            .Returns(persistence);

            sut = new MyDomainObject(store);
        }
Esempio n. 2
0
        public DomainObjectGrainTests()
        {
            A.CallTo(() => store.WithSnapshotsAndEventSourcing(typeof(MyDomainObject), id, A <HandleSnapshot <MyDomainState> > .Ignored, A <HandleEvent> .Ignored))
            .Returns(persistence);

            sut = new MyDomainObject(store);
        }
        public void TestThatRaisePropertyChangedCallEventHandler()
        {
            var fixture      = new Fixture();
            var sender       = fixture.CreateAnonymous <object>();
            var propertyName = fixture.CreateAnonymous <string>();

            var domainObject = new MyDomainObject();

            Assert.That(domainObject, Is.Not.Null);

            var eventHandlerCalled = false;

            domainObject.PropertyChanged += ((s, e) =>
            {
                Assert.That(s, Is.Not.Null);
                Assert.That(s, Is.EqualTo(sender));
                Assert.That(e, Is.Not.Null);
                Assert.That(e.PropertyName, Is.Not.Null);
                Assert.That(e.PropertyName, Is.Not.Empty);
                Assert.That(e.PropertyName, Is.EqualTo(propertyName));
                eventHandlerCalled = true;
            });

            domainObject.RaisePropertyChanged(sender, propertyName);

            Assert.That(eventHandlerCalled, Is.True);
        }
Esempio n. 4
0
        public ActionResult Index()
        {
            var domainObject = new MyDomainObject();
            var task = new MyTask();

            task.DoSomething(domainObject);

            return View();
        }
Esempio n. 5
0
        public MainWindow()
        {
            InitializeComponent();

            var domainObject = new MyDomainObject();
            var task = new MyTask();

            task.DoSomething(domainObject);
        }
Esempio n. 6
0
        public DefaultDomainObjectRepositoryTests()
        {
            domainObject = new MyDomainObject(aggregateId, 123);

            streamNameResolver.Setup(x => x.GetStreamName(It.IsAny <Type>(), aggregateId)).Returns(streamName);

            factory.Setup(x => x.CreateNew(typeof(MyDomainObject), aggregateId)).Returns(domainObject);

            sut = new DefaultDomainObjectRepository(factory.Object, eventStore.Object, streamNameResolver.Object, eventDataFormatter.Object);
        }
        public void TestThatRaisePropertyChangedThrowsAnArgumentNullExceptionIfPropertyNameIsEmpty()
        {
            var fixture = new Fixture();

            var domainObject = new MyDomainObject();

            Assert.That(domainObject, Is.Not.Null);

            Assert.Throws <ArgumentNullException>(() => domainObject.RaisePropertyChanged(fixture.CreateAnonymous <object>(), string.Empty));
        }
        public void TestThatRaisePropertyChangedThrowsAnArgumentNullExceptionIfSenderIsNull()
        {
            var fixture = new Fixture();

            var domainObject = new MyDomainObject();

            Assert.That(domainObject, Is.Not.Null);

            Assert.Throws <ArgumentNullException>(() => domainObject.RaisePropertyChanged(null, fixture.CreateAnonymous <string>()));
        }
        public LogSnapshotDomainObjectGrainTests()
        {
            A.CallTo(() => store.WithEventSourcing(typeof(MyDomainObject), id, A <HandleEvent> .Ignored))
            .Returns(persistence);

            A.CallTo(() => store.GetSnapshotStore <MyDomainState>())
            .Returns(snapshotStore);

            sut = new MyDomainObject(store);
        }
Esempio n. 10
0
        public DefaultDomainObjectRepositoryTests()
        {
            domainObject = new MyDomainObject(aggregateId, 123);

            A.CallTo(() => nameResolver.GetStreamName(A <Type> .Ignored, aggregateId))
            .Returns(streamName);

            A.CallTo(() => factory.CreateNew <MyDomainObject>(aggregateId))
            .Returns(domainObject);

            sut = new DefaultDomainObjectRepository(eventStore, nameResolver, formatter);
        }
        public void TestThatRaisePropertyChangedReturnsIfEventHandlerNotSet()
        {
            var fixture      = new Fixture();
            var sender       = fixture.CreateAnonymous <object>();
            var propertyName = fixture.CreateAnonymous <string>();

            var domainObject = new MyDomainObject();

            Assert.That(domainObject, Is.Not.Null);

            domainObject.RaisePropertyChanged(sender, propertyName);
        }
Esempio n. 12
0
        public AggregateHandlerTests()
        {
            sut = new AggregateHandler(factory, repository);

            domainObject =
                new MyDomainObject(Guid.NewGuid(), 1)
                .RaiseNewEvent(event1)
                .RaiseNewEvent(event2);

            context = new CommandContext(new MyCommand {
                AggregateId = domainObject.Id
            });
        }
Esempio n. 13
0
        public void TestGreaterThanRuleCrossField()
        {
            Engine engine = new Engine();

            engine.For <MyDomainObject <int> >()
            .Setup(m => m.Value1)
            .MustBeGreaterThan(a => a.Value2);

            Assert.IsFalse(engine.Validate(new MyDomainObject <int>(3, 4)));
            Assert.IsFalse(engine.Validate(new MyDomainObject <int>(3, 3)));
            Assert.IsTrue(engine.Validate(new MyDomainObject <int>(3, 2)));

            TestingValidationReport v = new TestingValidationReport(engine);
            MyDomainObject <int>    o = new MyDomainObject <int>(3, 4);

            v.Validate(o);
            v.AssertError(o, p1 => p1.Value1, RuleKinds.GreaterThanRule, 4);
        }
Esempio n. 14
0
        public async Task Create_with_task_should_create_domain_object_and_save()
        {
            MyDomainObject passedDomainObject = null;

            await sut.CreateAsync <MyDomainObject>(context, async x =>
            {
                x.RaiseEvent(new MyEvent());

                await Task.Yield();

                passedDomainObject = x;
            });

            Assert.Equal(domainObject, passedDomainObject);
            Assert.NotNull(context.Result <EntityCreatedResult <Guid> >());

            A.CallTo(() => persistence.WriteEventsAsync(A <IEnumerable <Envelope <IEvent> > > .Ignored))
            .MustHaveHappened();
        }
Esempio n. 15
0
        public async Task Update_synced_should_create_domain_object_and_save()
        {
            MyDomainObject passedDomainObject = null;

            await sut.UpdateSyncedAsync <MyDomainObject>(context, x =>
            {
                x.RaiseEvent(new MyEvent());
                x.RaiseEvent(new MyEvent());

                passedDomainObject = x;
            });

            Assert.Equal(2, domainObject.Snapshot.Version);
            Assert.Equal(domainObject, passedDomainObject);
            Assert.NotNull(context.Result <EntitySavedResult>());

            A.CallTo(() => persistence.WriteEventsAsync(A <IEnumerable <Envelope <IEvent> > > .Ignored))
            .MustHaveHappened();
        }
Esempio n. 16
0
        public void TestBetweenRuleCrossFieldLessAndGreater()
        {
            Engine engine = new Engine();

            engine.For <MyDomainObject <int> >()
            .Setup(m => m.Value1)
            .MustBeBetween(a => a.Value2, a => a.Value3);

            Assert.IsTrue(engine.Validate(new MyDomainObject <int>(3, 2, 5)));
            Assert.IsTrue(engine.Validate(new MyDomainObject <int>(3, 3, 3)));
            Assert.IsFalse(engine.Validate(new MyDomainObject <int>(3, 4, 5)));
            Assert.IsFalse(engine.Validate(new MyDomainObject <int>(3, 1, 2)));

            TestingValidationReport v = new TestingValidationReport(engine);
            MyDomainObject <int>    o = new MyDomainObject <int>(4, 1, 3);

            v.Validate(o);
            v.AssertError(o, p1 => p1.Value1, RuleKinds.BetweenRule, 1, 3, 4, BetweenRuleBoundsOption.BothInclusive);
        }
Esempio n. 17
0
        public void TestLessThanOrEqualToRuleCrossField()
        {
            var builder = new Fluent.FluentBuilder();

            builder.For <MyDomainObject <int> >()
            .Setup(m => m.Value1)
            .MustBeLessThanOrEqualTo(a => a.Value2);

            var engine = builder.Build();

            Assert.IsTrue(engine.Validate(new MyDomainObject <int>(3, 4)));
            Assert.IsTrue(engine.Validate(new MyDomainObject <int>(3, 3)));
            Assert.IsFalse(engine.Validate(new MyDomainObject <int>(3, 2)));

            TestingValidationReport v = new TestingValidationReport(engine);
            MyDomainObject <int>    o = new MyDomainObject <int>(4, 3);

            v.Validate(o);
            v.AssertError(o, p1 => p1.Value1, RuleKinds.LessThanOrEqualToRule, 3);
        }
Esempio n. 18
0
        public void TestBetweenRuleCrossFieldLess()
        {
            Engine engine = new Engine();

            engine.For <MyDomainObject <int> >()
            .Setup(m => m.Value1)
            .MustBeBetween(6, a => a.Value2);

            Assert.IsTrue(engine.Validate(new MyDomainObject <int>(7, 10)));
            Assert.IsTrue(engine.Validate(new MyDomainObject <int>(6, 6)));
            Assert.IsFalse(engine.Validate(new MyDomainObject <int>(5, 10)));
            Assert.IsFalse(engine.Validate(new MyDomainObject <int>(8, 7)));

            TestingValidationReport v = new TestingValidationReport(engine);
            MyDomainObject <int>    o = new MyDomainObject <int>(4, 3);

            v.Validate(o);

            v.AssertError(o, p1 => p1.Value1, RuleKinds.BetweenRule, 6, 3, 4, BetweenRuleBoundsOption.BothInclusive);
        }
Esempio n. 19
0
        public void TestBetweenRuleCrossFieldGreater()
        {
            Engine engine = new Engine();

            engine.For <MyDomainObject <int> >()
            .Setup(m => m.Value1)
            .MustBeBetween(a => a.Value2, 10);

            Assert.IsTrue(engine.Validate(new MyDomainObject <int>(7, 5)));
            Assert.IsTrue(engine.Validate(new MyDomainObject <int>(6, 6)));
            Assert.IsFalse(engine.Validate(new MyDomainObject <int>(5, 6)));
            Assert.IsFalse(engine.Validate(new MyDomainObject <int>(11, 15)));

            TestingValidationReport v = new TestingValidationReport(engine);
            MyDomainObject <int>    o = new MyDomainObject <int>(3, 4);

            engine.Validate(o, v, ValidationReportDepth.FieldShortCircuit);

            v.AssertError(o, p1 => p1.Value1, RuleKinds.BetweenRule, 4, 10, 3, BetweenRuleBoundsOption.BothInclusive);
        }
Esempio n. 20
0
        public async Task Create_sync_should_create_domain_object_and_save()
        {
            A.CallTo(() => factory.CreateNew <MyDomainObject>(domainObject.Id))
            .Returns(domainObject);

            A.CallTo(() => repository.SaveAsync(domainObject, A <ICollection <Envelope <IEvent> > > .Ignored, A <Guid> .Ignored))
            .Returns(TaskHelper.Done);

            MyDomainObject passedDomainObject = null;

            await sut.CreateAsync <MyDomainObject>(context, x =>
            {
                passedDomainObject = x;
            });

            Assert.Equal(domainObject, passedDomainObject);
            Assert.NotNull(context.Result <EntityCreatedResult <Guid> >());

            A.CallTo(() => repository.SaveAsync(domainObject, A <ICollection <Envelope <IEvent> > > .Ignored, A <Guid> .Ignored)).MustHaveHappened();
        }
Esempio n. 21
0
        public async Task Create_sync_should_create_domain_object_and_save()
        {
            factory.Setup(x => x.CreateNew(typeof(MyDomainObject), domainObject.Id))
            .Returns(domainObject)
            .Verifiable();

            repository.Setup(x => x.SaveAsync(domainObject, It.IsAny <ICollection <Envelope <IEvent> > >(), It.IsAny <Guid>()))
            .Returns(TaskHelper.Done)
            .Verifiable();

            MyDomainObject passedDomainObject = null;

            await sut.CreateAsync <MyDomainObject>(context, x =>
            {
                passedDomainObject = x;
            });

            Assert.Equal(domainObject, passedDomainObject);
            Assert.NotNull(context.Result <EntityCreatedResult <Guid> >());

            repository.VerifyAll();
        }
Esempio n. 22
0
        public async Task Update_sync_should_create_domain_object_and_save()
        {
            repository.Setup(x => x.GetByIdAsync <MyDomainObject>(command.AggregateId, null))
            .Returns(Task.FromResult(domainObject))
            .Verifiable();

            repository.Setup(x => x.SaveAsync(domainObject, It.IsAny <ICollection <Envelope <IEvent> > >(), It.IsAny <Guid>()))
            .Returns(TaskHelper.Done)
            .Verifiable();

            MyDomainObject passedDomainObject = null;

            await sut.UpdateAsync <MyDomainObject>(context, x =>
            {
                passedDomainObject = x;
            });

            Assert.Equal(domainObject, passedDomainObject);
            Assert.NotNull(context.Result <EntitySavedResult>());

            repository.VerifyAll();
        }
Esempio n. 23
0
 public MyDomainObjectWcfAdapter(MyDomainObject obj)
 {
     this._object = obj;
 }
Esempio n. 24
0
 public DomainObjectTests()
 {
     sut = new MyDomainObject(store);
 }
 public MyDomainObjectViewModel(MyDomainObject domainObject)
 {
     _domainObject = domainObject;
 }
Esempio n. 26
0
 public DomainObjectTests()
 {
     sut = new MyDomainObject(persistenceFactory);
 }
Esempio n. 27
0
        public void TestThatConstructorInitializeDomainObjectBase()
        {
            var domainObjectBase = new MyDomainObject();

            Assert.That(domainObjectBase, Is.Not.Null);
        }