コード例 #1
0
        public async Task ShouldGetAllTeachersAsync()
        {
            // given
            IEnumerable <TeacherContact> randomTeacherContacts   = CreateRandomTeacherContacts();
            List <TeacherContact>        inputTeacherContacts    = randomTeacherContacts.ToList();
            List <TeacherContact>        expectedTeacherContacts = inputTeacherContacts;

            foreach (TeacherContact inputTeacherContact in inputTeacherContacts)
            {
                await this.otripleSApiBroker.PostTeacherContactAsync(inputTeacherContact);
            }

            // when
            IEnumerable <TeacherContact> actualTeacherContacts =
                await this.otripleSApiBroker.GetAllTeacherContactsAsync();

            // then
            foreach (TeacherContact expectedTeacherContact in expectedTeacherContacts)
            {
                TeacherContact actualTeacherContact =
                    actualTeacherContacts.FirstOrDefault(teacherContact =>
                                                         teacherContact.TeacherId == expectedTeacherContact.TeacherId &&
                                                         teacherContact.ContactId == expectedTeacherContact.ContactId);

                actualTeacherContact.Should().BeEquivalentTo(expectedTeacherContact,
                                                             options => options
                                                             .Excluding(teacherContact => teacherContact.Teacher)
                                                             .Excluding(teacherContact => teacherContact.Contact));

                await this.otripleSApiBroker.DeleteTeacherContactByIdAsync(
                    actualTeacherContact.TeacherId,
                    actualTeacherContact.ContactId);
            }
        }
        public async Task ShouldRetrieveTeacherContactById()
        {
            // given
            DateTimeOffset inputDateTime          = GetRandomDateTime();
            TeacherContact randomTeacherContact   = CreateRandomTeacherContact(inputDateTime);
            TeacherContact storageTeacherContact  = randomTeacherContact;
            TeacherContact expectedTeacherContact = storageTeacherContact;

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectTeacherContactByIdAsync(randomTeacherContact.TeacherId, randomTeacherContact.ContactId))
            .ReturnsAsync(randomTeacherContact);

            // when
            TeacherContact actualTeacherContact = await
                                                  this.teacherContactService.RetrieveTeacherContactByIdAsync(
                randomTeacherContact.TeacherId, randomTeacherContact.ContactId);

            // then
            actualTeacherContact.Should().BeEquivalentTo(expectedTeacherContact);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectTeacherContactByIdAsync(randomTeacherContact.TeacherId, randomTeacherContact.ContactId),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
コード例 #3
0
        public async Task ShouldPostTeacherContactAsync()
        {
            // given
            TeacherContact randomTeacherContact   = CreateRandomTeacherContact();
            TeacherContact inputTeacherContact    = randomTeacherContact;
            TeacherContact expectedTeacherContact = inputTeacherContact;

            // when
            await this.otripleSApiBroker.PostTeacherContactAsync(inputTeacherContact);

            TeacherContact actualTeacherContact =
                await this.otripleSApiBroker.GetTeacherContactByIdAsync(
                    inputTeacherContact.TeacherId,
                    inputTeacherContact.ContactId);

            // then
            actualTeacherContact.Should().BeEquivalentTo(expectedTeacherContact,
                                                         options => options
                                                         .Excluding(teacherContact => teacherContact.Teacher)
                                                         .Excluding(teacherContact => teacherContact.Contact));

            await this.otripleSApiBroker.DeleteTeacherContactByIdAsync(
                actualTeacherContact.TeacherId,
                actualTeacherContact.ContactId);
        }
コード例 #4
0
        public async Task ShouldAddTeacherContactAsync()
        {
            // given
            TeacherContact randomTeacherContact   = CreateRandomTeacherContact();
            TeacherContact inputTeacherContact    = randomTeacherContact;
            TeacherContact storageTeacherContact  = randomTeacherContact;
            TeacherContact expectedTeacherContact = storageTeacherContact;

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertTeacherContactAsync(inputTeacherContact))
            .ReturnsAsync(storageTeacherContact);

            // when
            TeacherContact actualTeacherContact =
                await this.teacherContactService.AddTeacherContactAsync(inputTeacherContact);

            // then
            actualTeacherContact.Should().BeEquivalentTo(expectedTeacherContact);

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertTeacherContactAsync(inputTeacherContact),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
コード例 #5
0
        public async Task ShouldRemoveTeacherContactAsync()
        {
            // given
            var            randomTeacherId      = Guid.NewGuid();
            var            randomContactId      = Guid.NewGuid();
            Guid           inputTeacherId       = randomTeacherId;
            Guid           inputContactId       = randomContactId;
            DateTimeOffset inputDateTime        = GetRandomDateTime();
            TeacherContact randomTeacherContact = CreateRandomTeacherContact(inputDateTime);

            randomTeacherContact.TeacherId = inputTeacherId;
            randomTeacherContact.ContactId = inputContactId;
            TeacherContact storageTeacherContact  = randomTeacherContact;
            TeacherContact expectedTeacherContact = storageTeacherContact;

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectTeacherContactByIdAsync(inputTeacherId, inputContactId))
            .ReturnsAsync(storageTeacherContact);

            this.storageBrokerMock.Setup(broker =>
                                         broker.DeleteTeacherContactAsync(storageTeacherContact))
            .ReturnsAsync(expectedTeacherContact);

            // when
            TeacherContact actualTeacherContact =
                await this.teacherContactService.RemoveTeacherContactByIdAsync(inputTeacherId, inputContactId);

            // then
            actualTeacherContact.Should().BeEquivalentTo(expectedTeacherContact);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectTeacherContactByIdAsync(inputTeacherId, inputContactId),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.DeleteTeacherContactAsync(storageTeacherContact),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
コード例 #6
0
        public async Task ShouldDeleteTeacherContactAsync()
        {
            // given
            TeacherContact randomTeacherContact = await PostRandomTeacherContactAsync();

            TeacherContact inputTeacherContact    = randomTeacherContact;
            TeacherContact expectedTeacherContact = inputTeacherContact;

            // when
            TeacherContact deletedTeacherContact =
                await DeleteTeacherContactAsync(inputTeacherContact);

            ValueTask <TeacherContact> getTeacherContactByIdTask =
                this.otripleSApiBroker.GetTeacherContactByIdAsync(
                    inputTeacherContact.TeacherId, inputTeacherContact.ContactId);

            // then
            deletedTeacherContact.Should().BeEquivalentTo(expectedTeacherContact);

            await Assert.ThrowsAsync <HttpResponseNotFoundException>(() =>
                                                                     getTeacherContactByIdTask.AsTask());
        }
コード例 #7
0
        public async Task ShouldGetAllTeacherContactsAsync()
        {
            // given
            Teacher randomTeacher = await PostRandomTeacherAsync();

            var randomTeacherContacts = new List <TeacherContact>();

            for (int i = 0; i < GetRandomNumber(); i++)
            {
                randomTeacherContacts.Add(await CreateRandomTeacherContactAsync(randomTeacher));
            }

            List <TeacherContact> inputTeacherContacts    = randomTeacherContacts.ToList();
            List <TeacherContact> expectedTeacherContacts = inputTeacherContacts;

            // when
            IEnumerable <TeacherContact> actualTeacherContacts =
                await this.otripleSApiBroker.GetAllTeacherContactsAsync();

            // then
            foreach (TeacherContact expectedTeacherContact in expectedTeacherContacts)
            {
                TeacherContact actualTeacherContact =
                    actualTeacherContacts.Single(teacherContact =>
                                                 teacherContact.TeacherId == expectedTeacherContact.TeacherId &&
                                                 teacherContact.ContactId == expectedTeacherContact.ContactId);

                actualTeacherContact.Should().BeEquivalentTo(expectedTeacherContact);

                await this.otripleSApiBroker.DeleteTeacherContactByIdAsync(
                    actualTeacherContact.TeacherId, actualTeacherContact.ContactId);

                await this.otripleSApiBroker.DeleteContactByIdAsync(actualTeacherContact.ContactId);
            }

            await this.otripleSApiBroker.DeleteTeacherByIdAsync(randomTeacher.Id);
        }