public void Emails_and_phone_numbers_cannot_be_duplicates()
        {
            var command = new RegisterSchool.Command()
            {
                Name        = "I Liceum Ogólnokształcące",
                City        = "Gdańsk",
                Address     = "Wały Piastowskie 6",
                ContactData = new[] {
                    new ContactData()
                    {
                        Name = "sekretariat", EmailAddress = EmailAddress.Parse("*****@*****.**"), PhoneNumber = PhoneNumber.Parse("58 301-67-34")
                    },
                    new ContactData()
                    {
                        Name = "dyrektor", EmailAddress = EmailAddress.Parse("*****@*****.**"), PhoneNumber = PhoneNumber.Parse("58 301-67-34")
                    }
                }
            };
            var school = new SchoolAggregate(SchoolId.New);
            var now    = NodaTime.SystemClock.Instance.GetCurrentInstant();

            var result = school.RegisterSchool(now, command, new ApplicationUser());

            Assert.False(result.IsSuccess);
            var error   = Assert.IsType <Error.ValidationFailed>(result.Error);
            var failure = Assert.Single(error.Failures);

            Assert.Equal(nameof(command.ContactData), failure.PropertyName);
            Assert.All(failure.Errors, message => Assert.Equal(RegisterSchool_Messages.ContactData_emails_and_phone_numbers_cannot_repeat_themselves, message));
        }
        public void Each_contact_must_contain_email_or_phone_number()
        {
            var command = new RegisterSchool.Command()
            {
                Name        = "I Liceum Ogólnokształcące",
                City        = "Gdańsk",
                Address     = "Wały Piastowskie 6",
                ContactData = new[] {
                    new ContactData()
                    {
                        Name = "sekretariat"
                    }
                }
            };
            var school = new SchoolAggregate(SchoolId.New);
            var now    = NodaTime.SystemClock.Instance.GetCurrentInstant();

            var result = school.RegisterSchool(now, command, new ApplicationUser());

            Assert.False(result.IsSuccess);
            var error = Assert.IsType <Error.ValidationFailed>(result.Error);

            Assert.Collection(error.Failures,
                              first => {
                Assert.Equal($"{nameof(command.ContactData)}[0].{nameof(ContactData.PhoneNumber)}", first.PropertyName);
                Assert.Single(first.Errors, RegisterSchool_Messages.Either_ContactData_PhoneNumber_or_ContactData_EmailAddress_must_be_provided);
            },
                              second =>
            {
                Assert.Equal($"{nameof(command.ContactData)}[0].{nameof(ContactData.EmailAddress)}", second.PropertyName);
                Assert.Single(second.Errors, RegisterSchool_Messages.Either_ContactData_PhoneNumber_or_ContactData_EmailAddress_must_be_provided);
            });
        }
Exemplo n.º 3
0
        private async Task <SchoolAggregate> RegisterSchool()
        {
            var school = new SchoolAggregate(SchoolId.New);
            var author = new ApplicationUser()
            {
                Id = Guid.NewGuid()
            };

            school.RegisterSchool(
                NodaTime.SystemClock.Instance.GetCurrentInstant() - NodaTime.Duration.FromDays(2),
                new RegisterSchool.Command()
            {
                Name        = "I Liceum Ogólnokształcące",
                City        = "Gdańsk",
                Address     = "Wały Piastowskie 6",
                ContactData = new[] {
                    new ContactData()
                    {
                        Name         = "sekretariat",
                        EmailAddress = EmailAddress.Parse("*****@*****.**"),
                        PhoneNumber  = PhoneNumber.Parse("58 301-67-34")
                    },
                }
            },
                author).IsSuccess.Should().BeTrue();
            await school.CommitAsync(
                Mock.Of <EventFlow.EventStores.IEventStore>(),
                Mock.Of <EventFlow.Snapshots.ISnapshotStore>(),
                EventFlow.Core.SourceId.New, CancellationToken.None);

            return(school);
        }
Exemplo n.º 4
0
        public void Command_must_contain__SchoolId_and_NoteId()
        {
            var school = new SchoolAggregate(SchoolId.With(default(Guid)));
            var author = new ApplicationUser();

            var command = new DeleteNote.Command()
            {
                SchoolId = default, NoteId = default
Exemplo n.º 5
0
        public void Command_must_contain_SchoolId_and_Content()
        {
            var school = new SchoolAggregate(SchoolId.With(default(Guid)));
            var author = new ApplicationUser();

            var command = new AddNote.Command()
            {
                SchoolId = default, Content = "    "
        public void After_registering_contact__aggregate_contains_ContactOccured_event()
        {
            var school          = new SchoolAggregate(SchoolId.New);
            var registeringUser = new ApplicationUser()
            {
                Id = Guid.NewGuid()
            };

            school.RegisterSchool(
                NodaTime.SystemClock.Instance.GetCurrentInstant() - NodaTime.Duration.FromDays(2),
                new RegisterSchool.Command()
            {
                Name        = "I Liceum Ogólnokształcące",
                City        = "Gdańsk",
                Address     = "Wały Piastowskie 6",
                ContactData = new[] {
                    new ContactData()
                    {
                        Name         = "sekretariat",
                        EmailAddress = EmailAddress.Parse("*****@*****.**"),
                        PhoneNumber  = PhoneNumber.Parse("58 301-67-34")
                    },
                }
            },
                registeringUser);

            var command = new RecordContact.Command()
            {
                SchoolId             = school.Id.GetGuid(),
                ContactTimestamp     = NodaTime.SystemClock.Instance.GetCurrentInstant() - NodaTime.Duration.FromDays(1),
                CommunicationChannel = CommunicationChannelType.OutgoingEmail,
                EmailAddress         = EmailAddress.Parse("*****@*****.**"),
                PhoneNumber          = null,
                ContactPersonName    = "Andrzej Strzelba",
                Content         = "treść",
                AdditionalNotes = "notatka"
            };
            var result = school.RecordContact(command, registeringUser, NodaTime.SystemClock.Instance.GetCurrentInstant());

            Assert.True(result.IsSuccess);

            var uncommittedEvent = Assert.Single(school.UncommittedEvents, @event => @event.AggregateEvent is ContactOccured);
            var @event           = Assert.IsType <ContactOccured>(uncommittedEvent.AggregateEvent);

            Assert.Equal(registeringUser.Id, @event.RecordingUserId);
            Assert.Equal(command.ContactTimestamp, @event.ContactTimestamp);
            Assert.Equal(CommunicationChannelType.OutgoingEmail, @event.CommunicationChannel);
            Assert.Equal(command.EmailAddress, @event.EmailAddress);
            Assert.Equal(command.PhoneNumber, @event.PhoneNumber);
            Assert.Equal("Andrzej Strzelba", @event.ContactPersonName);
            Assert.Equal("treść", @event.Content);
            Assert.Equal("notatka", @event.AdditionalNotes);
        }
        public void Command_must_be_executed_on_aggregate_with_matching_SchoolId()
        {
            var school        = new SchoolAggregate(SchoolId.New);
            var recordingUser = new ApplicationUser();

            var command = new RecordInitialAgreement.Command()
            {
                SchoolId = Guid.NewGuid()
            };

            Assert.Throws <AggregateMismatchException>(() =>
                                                       school.RecordInitialAgreement(NodaTime.SystemClock.Instance.GetCurrentInstant(), command, recordingUser));
        }
        public void SchoolId_must_point_to_existing_school()
        {
            var school        = new SchoolAggregate(SchoolId.New);
            var recordingUser = new ApplicationUser();

            var command = new RecordInitialAgreement.Command()
            {
                SchoolId           = school.Id.GetGuid(),
                AgreeingPersonName = "Andrzej Strzelba"
            };
            var result = school.RecordInitialAgreement(NodaTime.SystemClock.Instance.GetCurrentInstant(), command, recordingUser);

            Assert.False(result.IsSuccess);
            var error = Assert.IsType <Error.ResourceNotFound>(result.Error);

            Assert.Equal(Messages.School_not_found, error.Message);
        }
        public void After_registering_initial_agreement__aggregate_contains_InitialAgreementAchieved_event()
        {
            var school        = new SchoolAggregate(SchoolId.New);
            var recordingUser = new ApplicationUser()
            {
                Id = Guid.NewGuid()
            };

            school.RegisterSchool(
                NodaTime.SystemClock.Instance.GetCurrentInstant() - NodaTime.Duration.FromDays(2),
                new RegisterSchool.Command()
            {
                Name        = "I Liceum Ogólnokształcące",
                City        = "Gdańsk",
                Address     = "Wały Piastowskie 6",
                ContactData = new[] {
                    new ContactData()
                    {
                        Name         = "sekretariat",
                        EmailAddress = EmailAddress.Parse("*****@*****.**"),
                        PhoneNumber  = PhoneNumber.Parse("58 301-67-34")
                    },
                }
            },
                new ApplicationUser()
            {
                Id = Guid.NewGuid()
            });

            var command = new RecordInitialAgreement.Command()
            {
                SchoolId           = school.Id.GetGuid(),
                AgreeingPersonName = "Andrzej Strzelba",
                AdditionalNotes    = "test"
            };
            var result = school.RecordInitialAgreement(NodaTime.SystemClock.Instance.GetCurrentInstant(), command, recordingUser);

            result.IsSuccess.Should().BeTrue();

            school.HasAgreedInitially.Should().BeTrue();

            var uncommittedEvent = Assert.Single(school.UncommittedEvents, @event => @event.AggregateEvent is InitialAgreementAchieved);
            var @event           = Assert.IsType <InitialAgreementAchieved>(uncommittedEvent.AggregateEvent);

            @event.Should().BeEquivalentTo(new InitialAgreementAchieved(recordingUser.Id, "Andrzej Strzelba", "test"));
        }
        public void Request_Timestamp_cannot_be_later_than_current_timestamp()
        {
            var school          = new SchoolAggregate(SchoolId.New);
            var registeringUser = new ApplicationUser()
            {
                Id = Guid.NewGuid()
            };

            school.RegisterSchool(
                NodaTime.SystemClock.Instance.GetCurrentInstant() - NodaTime.Duration.FromDays(1),
                new RegisterSchool.Command()
            {
                Name        = "I Liceum Ogólnokształcące",
                City        = "Gdańsk",
                Address     = "Wały Piastowskie 6",
                ContactData = new[] {
                    new ContactData()
                    {
                        Name         = "sekretariat",
                        EmailAddress = EmailAddress.Parse("*****@*****.**"),
                        PhoneNumber  = PhoneNumber.Parse("58 301-67-34")
                    },
                }
            },
                registeringUser);

            var command = new RecordContact.Command()
            {
                SchoolId             = school.Id.GetGuid(),
                ContactTimestamp     = NodaTime.SystemClock.Instance.GetCurrentInstant() + NodaTime.Duration.FromDays(1),
                CommunicationChannel = CommunicationChannelType.OutgoingEmail,
                EmailAddress         = EmailAddress.Parse("*****@*****.**"),
                ContactPersonName    = "Andrzej Strzelba",
                Content = "treść"
            };
            var result = school.RecordContact(command, new ApplicationUser()
            {
                Id = Guid.NewGuid()
            }, NodaTime.SystemClock.Instance.GetCurrentInstant());

            Assert.False(result.IsSuccess);
            var error = Assert.IsType <Error.DomainError>(result.Error);

            Assert.Equal(RecordContact_Messages.Contact_timestamp_cannot_be_later_than_current_timestamp, error.Message);
        }
Exemplo n.º 11
0
        private async Task <Guid> AddNote(SchoolAggregate school, string content, ApplicationUser author)
        {
            var result = school.AddNote(
                new AddNote.Command()
            {
                Content = content, SchoolId = school.Id.GetGuid()
            },
                author, Now
                );

            result.IsSuccess.Should().BeTrue();
            await school.CommitAsync(
                Mock.Of <EventFlow.EventStores.IEventStore>(),
                Mock.Of <EventFlow.Snapshots.ISnapshotStore>(),
                EventFlow.Core.SourceId.New, CancellationToken.None);

            return(result.Value);
        }
        public void Command_must_contain__schoolId_communicationChannel_contactPersonName()
        {
            var school        = new SchoolAggregate(SchoolId.With(Guid.Empty));
            var recordingUser = new ApplicationUser();

            var command = new RecordInitialAgreement.Command()
            {
                AgreeingPersonName = "   ",
                SchoolId           = default
            };

            var result = school.RecordInitialAgreement(NodaTime.SystemClock.Instance.GetCurrentInstant(), command, recordingUser);

            Assert.False(result.IsSuccess);
            var error = Assert.IsType <Error.ValidationFailed>(result.Error);

            Assert.Contains(RecordInitialAgreement_Messages.SchoolId_cannot_be_empty, error.Failures[nameof(command.SchoolId)]);
            Assert.Contains(RecordInitialAgreement_Messages.ContactPersonName_cannot_be_empty, error.Failures[nameof(command.AgreeingPersonName)]);
        }
        public void Submission_must_contain__name_city_address_and_at_least_one_contact_with_email_or_phone_number()
        {
            var command = new RegisterSchool.Command()
            {
                Name        = string.Empty, City = string.Empty, Address = string.Empty,
                ContactData = Array.Empty <ContactData>()
            };
            var school = new SchoolAggregate(SchoolId.New);
            var now    = NodaTime.SystemClock.Instance.GetCurrentInstant();

            var result = school.RegisterSchool(now, command, new ApplicationUser());

            Assert.False(result.IsSuccess);
            var error = Assert.IsType <Error.ValidationFailed>(result.Error);

            Assert.Contains(RegisterSchool_Messages.SchoolName_CannotBeEmpty, error.Failures[nameof(command.Name)]);
            Assert.Contains(RegisterSchool_Messages.City_CannotBeEmpty, error.Failures[nameof(command.City)]);
            Assert.Contains(RegisterSchool_Messages.Address_Cannot_be_empty, error.Failures[nameof(command.Address)]);
            Assert.Contains(RegisterSchool_Messages.ContactData_cannot_be_empty, error.Failures[nameof(command.ContactData)]);
        }
        public void SchoolId_must_point_to_existing_school()
        {
            var school        = new SchoolAggregate(SchoolId.New);
            var recordingUser = new ApplicationUser();

            var command = new RecordContact.Command()
            {
                SchoolId             = school.Id.GetGuid(),
                ContactTimestamp     = NodaTime.SystemClock.Instance.GetCurrentInstant() - NodaTime.Duration.FromDays(1),
                CommunicationChannel = CommunicationChannelType.OutgoingEmail,
                EmailAddress         = EmailAddress.Parse("*****@*****.**"),
                ContactPersonName    = "Andrzej Strzelba",
                Content = "treść"
            };
            var result = school.RecordContact(command, recordingUser, NodaTime.SystemClock.Instance.GetCurrentInstant());

            Assert.False(result.IsSuccess);
            var error = Assert.IsType <Error.ResourceNotFound>(result.Error);

            Assert.Equal(Messages.School_not_found, error.Message);
        }
        public void Request_must_contain__SchoolId_Timestamp_CommunicationChannel_and_Content()
        {
            var school        = new SchoolAggregate(SchoolId.With(Guid.Empty));
            var recordingUser = new ApplicationUser();

            var command = new RecordContact.Command()
            {
                ContactPersonName = "   ",
                Content           = "   "
            };
            var result = school.RecordContact(command, recordingUser, NodaTime.SystemClock.Instance.GetCurrentInstant());

            Assert.False(result.IsSuccess);
            var error = Assert.IsType <Error.ValidationFailed>(result.Error);

            Assert.Contains(RecordContact_Messages.SchoolId_cannot_be_empty, error.Failures[nameof(command.SchoolId)]);
            Assert.Contains(RecordContact_Messages.Timestamp_cannot_be_empty, error.Failures[nameof(command.ContactTimestamp)]);
            Assert.Contains(RecordContact_Messages.CommunicationChannel_cannot_be_empty, error.Failures[nameof(command.CommunicationChannel)]);
            Assert.Contains(RecordContact_Messages.ContactPersonName_cannot_be_empty, error.Failures[nameof(command.ContactPersonName)]);
            Assert.Contains(RecordContact_Messages.Content_cannot_be_empty, error.Failures[nameof(command.Content)]);
        }
        public void If_CommunicationChannel_is_IncomingEmail__EmailAddress_must_be_provided()
        {
            var school        = new SchoolAggregate(SchoolId.New);
            var recordingUser = new ApplicationUser();

            var command = new RecordContact.Command()
            {
                SchoolId             = school.Id.GetGuid(),
                ContactTimestamp     = NodaTime.SystemClock.Instance.GetCurrentInstant() - NodaTime.Duration.FromDays(1),
                CommunicationChannel = CommunicationChannelType.IncomingEmail,
                ContactPersonName    = "Andrzej Strzelba",
                Content = "treść"
            };
            var result = school.RecordContact(command, recordingUser, NodaTime.SystemClock.Instance.GetCurrentInstant());

            Assert.False(result.IsSuccess);
            var error = Assert.IsType <Error.ValidationFailed>(result.Error);

            Assert.Contains(RecordContact_Messages.EmailAddress_cannot_be_empty_when_CommunicationChannel_is_IncomingEmail_or_OutgoingEmail,
                            error.Failures[nameof(command.EmailAddress)]);
        }
        public void After_submission__aggregate_contains_SchoolRegistered_event()
        {
            var command = new RegisterSchool.Command()
            {
                Name        = "I Liceum Ogólnokształcące",
                City        = "Gdańsk",
                Address     = "Wały Piastowskie 6",
                ContactData = new[] {
                    new ContactData()
                    {
                        Name         = "sekretariat",
                        EmailAddress = EmailAddress.Parse("*****@*****.**"),
                        PhoneNumber  = PhoneNumber.Parse("58 301-67-34")
                    },
                }
            };

            var school          = new SchoolAggregate(SchoolId.New);
            var registeringUser = new ApplicationUser()
            {
                Id = Guid.NewGuid()
            };
            var result = school.RegisterSchool(NodaTime.SystemClock.Instance.GetCurrentInstant(), command, registeringUser);

            Assert.True(result.IsSuccess);
            var uncommittedEvent = Assert.Single(school.UncommittedEvents, e => e.AggregateEvent is SchoolRegistered);
            var @event           = Assert.IsType <SchoolRegistered>(uncommittedEvent.AggregateEvent);

            Assert.Equal(registeringUser.Id, @event.RegisteringUserId);
            Assert.Equal(command.Name, @event.Name);
            Assert.Equal(command.City, @event.City);
            var contactData = Assert.Single(command.ContactData);

            Assert.Equal("sekretariat", contactData.Name);
            Assert.Equal(EmailAddress.Parse("*****@*****.**"), contactData.EmailAddress);
            Assert.Equal(PhoneNumber.Parse("58 301-67-34"), contactData.PhoneNumber);
        }