Beispiel #1
0
        public async Task ShouldRetrieveExamAttachmentByIdAsync()
        {
            // given
            ExamAttachment randomExamAttachment   = CreateRandomExamAttachment();
            ExamAttachment storageExamAttachment  = randomExamAttachment;
            ExamAttachment expectedExamAttachment = storageExamAttachment;

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectExamAttachmentByIdAsync(
                                             randomExamAttachment.ExamId,
                                             randomExamAttachment.AttachmentId))
            .ReturnsAsync(randomExamAttachment);

            // when
            ExamAttachment actualExamAttachment =
                await this.examAttachmentService.RetrieveExamAttachmentByIdAsync(
                    randomExamAttachment.ExamId,
                    randomExamAttachment.AttachmentId);

            // then
            actualExamAttachment.Should().BeEquivalentTo(expectedExamAttachment);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectExamAttachmentByIdAsync(
                                              randomExamAttachment.ExamId,
                                              randomExamAttachment.AttachmentId),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldGetAllExamAttachmentsAsync()
        {
            // given
            var randomExamAttachments = new List <ExamAttachment>();

            for (var i = 0; i <= GetRandomNumber(); i++)
            {
                ExamAttachment randomExamAttachment = await PostExamAttachmentAsync();

                randomExamAttachments.Add(randomExamAttachment);
            }

            List <ExamAttachment> inputExamAttachments    = randomExamAttachments;
            List <ExamAttachment> expectedExamAttachments = inputExamAttachments;

            // when
            List <ExamAttachment> actualExamAttachments =
                await this.otripleSApiBroker.GetAllExamAttachmentsAsync();

            // then
            foreach (ExamAttachment expectedExamAttachment in expectedExamAttachments)
            {
                ExamAttachment actualExamAttachment =
                    actualExamAttachments.Single(studentAttachment =>
                                                 studentAttachment.ExamId == expectedExamAttachment.ExamId);

                actualExamAttachment.Should().BeEquivalentTo(expectedExamAttachment);

                await DeleteExamAttachmentAsync(actualExamAttachment);
            }
        }
        public async Task ShouldRemoveExamAttachmentAsync()
        {
            // given
            var            randomExamId         = Guid.NewGuid();
            var            randomAttachmentId   = Guid.NewGuid();
            Guid           inputExamId          = randomExamId;
            Guid           inputAttachmentId    = randomAttachmentId;
            ExamAttachment randomExamAttachment = CreateRandomExamAttachment();

            randomExamAttachment.ExamId       = inputExamId;
            randomExamAttachment.AttachmentId = inputAttachmentId;
            ExamAttachment storageExamAttachment  = randomExamAttachment;
            ExamAttachment expectedExamAttachment = storageExamAttachment;

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectExamAttachmentByIdAsync(inputExamId, inputAttachmentId))
            .ReturnsAsync(storageExamAttachment);

            this.storageBrokerMock.Setup(broker =>
                                         broker.DeleteExamAttachmentAsync(storageExamAttachment))
            .ReturnsAsync(expectedExamAttachment);

            // when
            ExamAttachment actualExamAttachment =
                await this.examAttachmentService.RemoveExamAttachmentByIdAsync(
                    inputExamId, inputAttachmentId);

            // then
            actualExamAttachment.Should().BeEquivalentTo(expectedExamAttachment);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectExamAttachmentByIdAsync(inputExamId, inputAttachmentId),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.DeleteExamAttachmentAsync(storageExamAttachment),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldPostExamAttachmentAsync()
        {
            // given
            ExamAttachment randomExamAttachment = await CreateRandomExamAttachment();

            ExamAttachment inputExamAttachment    = randomExamAttachment;
            ExamAttachment expectedExamAttachment = inputExamAttachment;

            // when
            ExamAttachment actualExamAttachment =
                await this.otripleSApiBroker.PostExamAttachmentAsync(inputExamAttachment);

            ExamAttachment retrievedExamAttachment =
                await this.otripleSApiBroker.GetExamAttachmentByIdsAsync(
                    inputExamAttachment.ExamId,
                    inputExamAttachment.AttachmentId);

            // then
            actualExamAttachment.Should().BeEquivalentTo(expectedExamAttachment);
            retrievedExamAttachment.Should().BeEquivalentTo(expectedExamAttachment);
            await DeleteExamAttachmentAsync(actualExamAttachment);
        }
        public async Task ShouldDeleteExamAttachmentAsync()
        {
            // given
            ExamAttachment randomExamAttachment = await PostExamAttachmentAsync();

            ExamAttachment inputExamAttachment    = randomExamAttachment;
            ExamAttachment expectedExamAttachment = inputExamAttachment;

            // when
            ExamAttachment deletedExamAttachment =
                await DeleteExamAttachmentAsync(inputExamAttachment);

            ValueTask <ExamAttachment> getExamAttachmentByIdTask =
                this.otripleSApiBroker.GetExamAttachmentByIdsAsync(
                    inputExamAttachment.ExamId,
                    inputExamAttachment.AttachmentId);

            // then
            deletedExamAttachment.Should().BeEquivalentTo(expectedExamAttachment);

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