public async Task Author_can_edit_note()
        {
            // arrange
            using var client = await _fixture.BuildClient();

            await AuthorizeAsCoordinator1(client);

            var schoolResponse = await client.PostAsJsonAsync(
                Szlem.AspNetCore.Routes.v1.Schools.Register, 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")
                    },
                }
            });

            await PrintOutProblemDetailsIfFaulty(schoolResponse);

            var schoolId = await schoolResponse.Content.ReadAsAsync <Guid>();

            var addNoteResponse = await client.PostAsJsonAsync(
                Szlem.AspNetCore.Routes.v1.Schools.AddNote,
                new AddNote.Command()
            {
                SchoolId = schoolId, Content = "test"
            });

            await PrintOutProblemDetailsIfFaulty(addNoteResponse);

            var noteId = await addNoteResponse.Content.ReadAsAsync <Guid>();


            // act
            await AuthorizeAsCoordinator1(client);

            var editNoteResponse = await client.PostAsJsonAsync(
                Szlem.AspNetCore.Routes.v1.Schools.EditNote,
                new EditNote.Command()
            {
                SchoolId = schoolId, NoteId = noteId, Content = "test2"
            });


            // assert
            await PrintOutProblemDetailsIfFaulty(editNoteResponse);

            editNoteResponse.IsSuccessStatusCode.Should().BeTrue();
            var school = await _fixture.Services.GetRequiredService <EventFlow.Aggregates.IAggregateStore>()
                         .LoadAsync <SchoolAggregate, SchoolId>(SchoolId.With(schoolId), CancellationToken.None);

            school.Notes.Should().ContainSingle()
            .Which.Should().BeEquivalentTo(new { NoteId = noteId, Content = "test2" });
        }
Пример #2
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 = "    "
Пример #3
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
        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 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 async Task After_submission__database_contains_school_aggregate()
        {
            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")
                    },
                }
            };

            Guid guid;
            var  sp = new ServiceProviderBuilder().BuildServiceProvider();

            using (var scope = sp.CreateScope())
            {
                var userAccessor = Mock.Of <IUserAccessor>(
                    mock => mock.GetUser() == Task.FromResult(new ApplicationUser()
                {
                    Id = Guid.NewGuid()
                }),
                    MockBehavior.Strict);
                var aggregateStore = scope.ServiceProvider.GetRequiredService <IAggregateStore>();
                var handler        = new RegisterSchoolHandler(NodaTime.SystemClock.Instance, userAccessor, aggregateStore);
                var result         = await handler.Handle(command, CancellationToken.None);

                Assert.True(result.IsSuccess);
                Assert.IsType <Guid>(result.Value);
                guid = result.Value;
            }

            using (var scope = sp.CreateScope())
            {
                var aggregateStore = scope.ServiceProvider.GetRequiredService <IAggregateStore>();
                var school         = await aggregateStore.LoadAsync <SchoolAggregate, SchoolId>(SchoolId.With(guid), CancellationToken.None);

                Assert.NotNull(school);
                Assert.False(school.IsNew);
            }
        }