Esempio n. 1
0
        public async Task ShouldPutStudentGuardianAsync()
        {
            // given
            Student inputStudent = await PostStudentAsync();

            Guardian inputGuardian = await PostGuardianAsync();

            StudentGuardian randomStudentGuardian = CreateRandomStudentGuardian(inputStudent.Id, inputGuardian.Id);
            StudentGuardian inputStudentGuardian  = randomStudentGuardian;

            await this.otripleSApiBroker.PostStudentGuardianAsync(inputStudentGuardian);

            StudentGuardian modifiedStudentGuardian = randomStudentGuardian.DeepClone();

            modifiedStudentGuardian.UpdatedDate = DateTimeOffset.UtcNow;

            // when
            await this.otripleSApiBroker.PutStudentGuardianAsync(modifiedStudentGuardian);

            StudentGuardian actualStudentGuardian =
                await this.otripleSApiBroker.GetStudentGuardianAsync(
                    randomStudentGuardian.StudentId,
                    randomStudentGuardian.GuardianId);

            // then
            actualStudentGuardian.Should().BeEquivalentTo(modifiedStudentGuardian);

            await this.otripleSApiBroker.DeleteStudentGuardianAsync(actualStudentGuardian.StudentId,
                                                                    actualStudentGuardian.GuardianId);

            await this.otripleSApiBroker.DeleteGuardianByIdAsync(actualStudentGuardian.GuardianId);

            await this.otripleSApiBroker.DeleteStudentByIdAsync(actualStudentGuardian.StudentId);
        }
        public async Task ShouldRetrieveStudentGuardianById()
        {
            // given
            DateTimeOffset  inputDateTime           = GetRandomDateTime();
            StudentGuardian randomStudentGuardian   = CreateRandomStudentGuardian(inputDateTime);
            StudentGuardian storageStudentGuardian  = randomStudentGuardian;
            StudentGuardian expectedStudentGuardian = storageStudentGuardian;

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentGuardianByIdAsync(randomStudentGuardian.StudentId, randomStudentGuardian.GuardianId))
            .Returns(new ValueTask <StudentGuardian>(randomStudentGuardian));

            // when
            StudentGuardian actualStudentGuardian = await
                                                    this.studentGuardianService.RetrieveStudentGuardianByIdAsync(randomStudentGuardian.StudentId, randomStudentGuardian.GuardianId);

            // then
            actualStudentGuardian.Should().BeEquivalentTo(expectedStudentGuardian);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectStudentGuardianByIdAsync(randomStudentGuardian.StudentId, randomStudentGuardian.GuardianId),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Esempio n. 3
0
        public async Task ShouldPostStudentGuardianAsync()
        {
            // given
            Student persistedStudent = await PostStudentAsync();

            Guardian persistedGuardian = await PostGuardianAsync();

            StudentGuardian randomStudentGuardian = CreateRandomStudentGuardian(
                persistedStudent.Id,
                persistedGuardian.Id);

            StudentGuardian inputStudentGuardian    = randomStudentGuardian;
            StudentGuardian expectedStudentGuardian = inputStudentGuardian;

            // when
            StudentGuardian persistedStudentGuardian =
                await this.otripleSApiBroker.PostStudentGuardianAsync(inputStudentGuardian);

            StudentGuardian actualStudentGuardian =
                await this.otripleSApiBroker.GetStudentGuardianAsync(persistedStudentGuardian.StudentId, persistedStudentGuardian.GuardianId);

            // then
            actualStudentGuardian.Should().BeEquivalentTo(expectedStudentGuardian);

            await this.otripleSApiBroker.DeleteStudentGuardianAsync(actualStudentGuardian.StudentId,
                                                                    actualStudentGuardian.GuardianId);

            await this.otripleSApiBroker.DeleteGuardianByIdAsync(actualStudentGuardian.GuardianId);

            await this.otripleSApiBroker.DeleteStudentByIdAsync(actualStudentGuardian.StudentId);
        }
        public async Task ShouldGetAllStudentGuardiansAsync()
        {
            // given
            var randomStudentGuardians = new List <StudentGuardian>();

            for (var i = 0; i <= GetRandomNumber(); i++)
            {
                StudentGuardian randomStudentGuardian = await PostStudentGuardianAsync();

                randomStudentGuardians.Add(randomStudentGuardian);
            }

            List <StudentGuardian> inputStudentGuardians    = randomStudentGuardians;
            List <StudentGuardian> expectedStudentGuardians = inputStudentGuardians;

            // when
            List <StudentGuardian> actualStudentGuardians =
                await this.otripleSApiBroker.GetAllStudentGuardiansAsync();

            // then
            foreach (StudentGuardian expectedStudentGuardian in expectedStudentGuardians)
            {
                StudentGuardian actualStudentGuardian =
                    actualStudentGuardians.Single(studentGuardian =>
                                                  studentGuardian.StudentId == expectedStudentGuardian.StudentId);

                actualStudentGuardian.Should().BeEquivalentTo(expectedStudentGuardian);

                await DeleteStudentGuardianAsync(actualStudentGuardian);
            }
        }
        public async Task ShouldModifyStudentGuardianAsync()
        {
            // given
            int             randomNumber                       = GetRandomNumber();
            int             randomDays                         = randomNumber;
            DateTimeOffset  randomDate                         = GetRandomDateTime();
            DateTimeOffset  randomInputDate                    = GetRandomDateTime();
            StudentGuardian randomStudentGuardian              = CreateRandomStudentGuardian(randomInputDate);
            StudentGuardian inputStudentGuardian               = randomStudentGuardian;
            StudentGuardian afterUpdateStorageStudentGuardian  = inputStudentGuardian;
            StudentGuardian expectedStudentGuardian            = afterUpdateStorageStudentGuardian;
            StudentGuardian beforeUpdateStorageStudentGuardian = randomStudentGuardian.DeepClone();

            inputStudentGuardian.UpdatedDate = randomDate;
            Guid studentId  = inputStudentGuardian.StudentId;
            Guid guardianId = inputStudentGuardian.GuardianId;

            this.dateTimeBrokerMock.Setup(broker =>
                                          broker.GetCurrentDateTime())
            .Returns(randomDate);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentGuardianByIdAsync(studentId, guardianId))
            .ReturnsAsync(beforeUpdateStorageStudentGuardian);

            this.storageBrokerMock.Setup(broker =>
                                         broker.UpdateStudentGuardianAsync(inputStudentGuardian))
            .ReturnsAsync(afterUpdateStorageStudentGuardian);

            // when
            StudentGuardian actualStudentGuardian =
                await this.studentGuardianService.ModifyStudentGuardianAsync(inputStudentGuardian);

            // then
            actualStudentGuardian.Should().BeEquivalentTo(expectedStudentGuardian);

            this.dateTimeBrokerMock.Verify(broker =>
                                           broker.GetCurrentDateTime(),
                                           Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectStudentGuardianByIdAsync(studentId, guardianId),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.UpdateStudentGuardianAsync(inputStudentGuardian),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Esempio n. 6
0
        public async Task ShouldGetAllStudentGuardiansAsync()
        {
            // given
            IEnumerable <StudentGuardian> randomStudentGuardians = GetRandomStudentGuardians();
            IEnumerable <StudentGuardian> inputStudentGuardians  = randomStudentGuardians;
            List <Student>  inputStudents  = new List <Student>();
            List <Guardian> inputGuardians = new List <Guardian>();

            foreach (StudentGuardian studentGuardian in inputStudentGuardians)
            {
                Student  randomStudent  = CreateRandomStudent();
                Student  inputStudent   = randomStudent;
                Guardian randomGuardian = CreateRandomGuardian();
                Guardian inputGuardian  = randomGuardian;
                studentGuardian.StudentId  = inputStudent.Id;
                studentGuardian.GuardianId = inputGuardian.Id;
                inputStudents.Add(inputStudent);
                inputGuardians.Add(inputGuardian);

                await this.otripleSApiBroker.PostStudentAsync(inputStudent);

                await this.otripleSApiBroker.PostGuardianAsync(inputGuardian);

                await this.otripleSApiBroker.PostStudentGuardianAsync(studentGuardian);
            }

            List <StudentGuardian> expectedStudentGuardians = inputStudentGuardians.ToList();

            // when
            List <StudentGuardian> actualStudentGuardians = await this.otripleSApiBroker.GetAllStudentGuardiansAsync();

            // then
            foreach (StudentGuardian expectedStudentGuardian in expectedStudentGuardians)
            {
                StudentGuardian actualStudentGuardian = actualStudentGuardians.Single(studentGuardian => studentGuardian.StudentId == expectedStudentGuardian.StudentId);
                actualStudentGuardian.Should().BeEquivalentTo(expectedStudentGuardian);

                await this.otripleSApiBroker.DeleteStudentGuardianAsync(actualStudentGuardian.StudentId, actualStudentGuardian.GuardianId);

                await this.otripleSApiBroker.DeleteGuardianByIdAsync(actualStudentGuardian.GuardianId);

                await this.otripleSApiBroker.DeleteStudentByIdAsync(actualStudentGuardian.StudentId);
            }
        }
        public async Task ShouldRemoveStudentGuardianAsync()
        {
            // given
            var             randomStudentId       = Guid.NewGuid();
            var             randomGuardianId      = Guid.NewGuid();
            Guid            inputStudentId        = randomStudentId;
            Guid            inputGuardianId       = randomGuardianId;
            DateTimeOffset  inputDateTime         = GetRandomDateTime();
            StudentGuardian randomStudentGuardian = CreateRandomStudentGuardian(inputDateTime);

            randomStudentGuardian.StudentId  = inputStudentId;
            randomStudentGuardian.GuardianId = inputGuardianId;
            StudentGuardian storageStudentGuardian  = randomStudentGuardian;
            StudentGuardian expectedStudentGuardian = storageStudentGuardian;

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentGuardianByIdAsync(inputStudentId, inputGuardianId))
            .ReturnsAsync(storageStudentGuardian);

            this.storageBrokerMock.Setup(broker =>
                                         broker.DeleteStudentGuardianAsync(storageStudentGuardian))
            .ReturnsAsync(expectedStudentGuardian);

            // when
            StudentGuardian actualStudentGuardian =
                await this.studentGuardianService.RemoveStudentGuardianByIdsAsync(inputStudentId, inputGuardianId);

            // then
            actualStudentGuardian.Should().BeEquivalentTo(expectedStudentGuardian);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectStudentGuardianByIdAsync(inputStudentId, inputGuardianId),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.DeleteStudentGuardianAsync(storageStudentGuardian),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldPostStudentGuardianAsync()
        {
            // given
            StudentGuardian randomStudentGuardian = await CreateRandomStudentGuardian();

            StudentGuardian inputStudentGuardian    = randomStudentGuardian;
            StudentGuardian expectedStudentGuardian = inputStudentGuardian;

            // when
            await this.otripleSApiBroker.PostStudentGuardianAsync(inputStudentGuardian);

            StudentGuardian actualStudentGuardian =
                await this.otripleSApiBroker.GetStudentGuardianByIdsAsync(
                    inputStudentGuardian.StudentId,
                    inputStudentGuardian.GuardianId);

            // then
            actualStudentGuardian.Should().BeEquivalentTo(expectedStudentGuardian);
            await DeleteStudentGuardianAsync(actualStudentGuardian);
        }
        public async Task ShouldAddStudentStudentGuardianAsync()
        {
            // given
            DateTimeOffset  randomDateTime        = GetRandomDateTime();
            DateTimeOffset  dateTime              = randomDateTime;
            StudentGuardian randomStudentGuardian = CreateRandomStudentGuardian(randomDateTime);

            randomStudentGuardian.UpdatedBy = randomStudentGuardian.CreatedBy;
            StudentGuardian inputStudentGuardian    = randomStudentGuardian;
            StudentGuardian storageStudentGuardian  = randomStudentGuardian;
            StudentGuardian expectedStudentGuardian = storageStudentGuardian;

            this.dateTimeBrokerMock.Setup(broker =>
                                          broker.GetCurrentDateTime())
            .Returns(dateTime);

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertStudentGuardianAsync(inputStudentGuardian))
            .ReturnsAsync(storageStudentGuardian);

            // when
            StudentGuardian actualStudentGuardian =
                await this.studentGuardianService.AddStudentGuardianAsync(inputStudentGuardian);

            // then
            actualStudentGuardian.Should().BeEquivalentTo(expectedStudentGuardian);

            this.dateTimeBrokerMock.Verify(broker =>
                                           broker.GetCurrentDateTime(),
                                           Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertStudentGuardianAsync(inputStudentGuardian),
                                          Times.Once);

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldDeleteStudentGuardianAsync()
        {
            // given
            StudentGuardian randomStudentGuardian = await PostStudentGuardianAsync();

            StudentGuardian inputStudentGuardian    = randomStudentGuardian;
            StudentGuardian expectedStudentGuardian = inputStudentGuardian;

            // when
            StudentGuardian deletedStudentGuardian =
                await DeleteStudentGuardianAsync(inputStudentGuardian);

            ValueTask <StudentGuardian> getStudentGuardianByIdTask =
                this.otripleSApiBroker.GetStudentGuardianByIdsAsync(
                    inputStudentGuardian.StudentId,
                    inputStudentGuardian.GuardianId);

            // then
            deletedStudentGuardian.Should().BeEquivalentTo(expectedStudentGuardian);

            await Assert.ThrowsAsync <HttpResponseNotFoundException>(() =>
                                                                     getStudentGuardianByIdTask.AsTask());
        }