public async Task ShouldGetAllCalendarEntriesAsync()
        {
            //given
            var randomCalendarEntries = new List <CalendarEntry>();

            for (var j = 0; j <= GetRandomNumber(); j++)
            {
                randomCalendarEntries.Add(await PostRandomCalendarEntryAsync());
            }

            List <CalendarEntry> inputedCalendarEntries  = randomCalendarEntries;
            List <CalendarEntry> expectedCalendarEntries = inputedCalendarEntries;

            //When
            List <CalendarEntry> actualcalendarEntries =
                await this.otripleSApiBroker.GetAllCalendarEntriesAsync();

            //then
            foreach (CalendarEntry expectedCalendarEntry in expectedCalendarEntries)
            {
                CalendarEntry actualCalendarEntry =
                    actualcalendarEntries.Single(calendarEntry =>
                                                 calendarEntry.Id == expectedCalendarEntry.Id);

                actualCalendarEntry.Should().BeEquivalentTo(expectedCalendarEntry);
                await DeleteCalendarEntryAsync(actualCalendarEntry);
            }
        }
        public async Task ShouldRetrieveCalendarEntryByIdAsync()
        {
            // given
            Guid           randomCalendarEntryId = Guid.NewGuid();
            Guid           inputCalendarEntryId  = randomCalendarEntryId;
            DateTimeOffset randomDateTime        = GetRandomDateTime();
            CalendarEntry  randomCalendarEntry   = CreateRandomCalendarEntry(randomDateTime);
            CalendarEntry  storageCalendarEntry  = randomCalendarEntry;
            CalendarEntry  expectedCalendarEntry = storageCalendarEntry;

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectCalendarEntryByIdAsync(inputCalendarEntryId))
            .ReturnsAsync(storageCalendarEntry);

            // when
            CalendarEntry actualCalendarEntry =
                await this.calendarEntryService.RetrieveCalendarEntryByIdAsync(
                    inputCalendarEntryId);

            // then
            actualCalendarEntry.Should().BeEquivalentTo(expectedCalendarEntry);

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectCalendarEntryByIdAsync(inputCalendarEntryId),
                                          Times.Once);

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldModifyCalendarEntryAsync()
        {
            // given
            DateTimeOffset randomDate                       = GetRandomDateTime();
            DateTimeOffset randomInputDate                  = GetRandomDateTime();
            CalendarEntry  randomCalendarEntry              = CreateRandomCalendarEntry(randomInputDate);
            CalendarEntry  inputCalendarEntry               = randomCalendarEntry;
            CalendarEntry  afterUpdateStorageCalendarEntry  = inputCalendarEntry;
            CalendarEntry  expectedCalendarEntry            = afterUpdateStorageCalendarEntry;
            CalendarEntry  beforeUpdateStorageCalendarEntry = randomCalendarEntry.DeepClone();

            inputCalendarEntry.UpdatedDate = randomDate;
            Guid calendarEntryId = inputCalendarEntry.Id;

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

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectCalendarEntryByIdAsync(calendarEntryId))
            .ReturnsAsync(beforeUpdateStorageCalendarEntry);

            this.storageBrokerMock.Setup(broker =>
                                         broker.UpdateCalendarEntryAsync(inputCalendarEntry))
            .ReturnsAsync(afterUpdateStorageCalendarEntry);

            // when
            CalendarEntry actualCalendarEntry =
                await this.calendarEntryService.ModifyCalendarEntryAsync(inputCalendarEntry);

            // then
            actualCalendarEntry.Should().BeEquivalentTo(expectedCalendarEntry);

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectCalendarEntryByIdAsync(calendarEntryId),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.UpdateCalendarEntryAsync(inputCalendarEntry),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldPutCalendarEntryAsync()
        {
            // given
            CalendarEntry randomCalendarEntry = await PostRandomCalendarEntryAsync();

            CalendarEntry modifiedCalendarEntry = await UpdateCalendarEntryRandom(randomCalendarEntry);

            // when
            await this.otripleSApiBroker.PutCalendarEntryAsync(modifiedCalendarEntry);

            CalendarEntry actualCalendarEntry =
                await this.otripleSApiBroker.GetCalendarEntryByIdAsync(randomCalendarEntry.Id);

            // then
            actualCalendarEntry.Should().BeEquivalentTo(modifiedCalendarEntry);
            await DeleteCalendarEntryAsync(actualCalendarEntry);
        }
        public async Task ShouldPostCalendarEntryAsync()
        {
            // given
            CalendarEntry randomCalendarEntry = await CreateRandomCalendarEntry();

            CalendarEntry inputCalendarEntry    = randomCalendarEntry;
            CalendarEntry expectedCalendarEntry = inputCalendarEntry;

            // when
            await this.otripleSApiBroker.PostCalendarEntryAsync(inputCalendarEntry);

            CalendarEntry actualCalendarEntry =
                await this.otripleSApiBroker.GetCalendarEntryByIdAsync(inputCalendarEntry.Id);

            // then
            actualCalendarEntry.Should().BeEquivalentTo(expectedCalendarEntry);
            await DeleteCalendarEntryAsync(actualCalendarEntry);
        }
        public async Task ShouldDeleteCalendarAsync()
        {
            //given
            CalendarEntry randomCalendarEntry = await PostRandomCalendarEntryAsync();

            CalendarEntry inputCalendarEntry    = randomCalendarEntry;
            CalendarEntry expectedCalendarEntry = inputCalendarEntry;

            //when
            CalendarEntry deletedCalendarEntry =
                await DeleteCalendarEntryAsync(inputCalendarEntry);

            ValueTask <CalendarEntry> getCalendarEntryByIdTask =
                this.otripleSApiBroker.GetCalendarEntryByIdAsync(inputCalendarEntry.Id);

            // then
            deletedCalendarEntry.Should().BeEquivalentTo(expectedCalendarEntry);

            await Assert.ThrowsAsync <HttpResponseNotFoundException>(() =>
                                                                     getCalendarEntryByIdTask.AsTask());
        }
        public async Task ShouldAddCalendarEntryAsync()
        {
            // given
            DateTimeOffset randomDateTime      = GetRandomDateTime();
            DateTimeOffset dateTime            = randomDateTime;
            CalendarEntry  randomCalendarEntry = CreateRandomCalendarEntry(dateTime);
            CalendarEntry  inputCalendarEntry  = randomCalendarEntry;

            inputCalendarEntry.UpdatedBy   = inputCalendarEntry.CreatedBy;
            inputCalendarEntry.UpdatedDate = inputCalendarEntry.CreatedDate;
            CalendarEntry expectedCalendarEntry = inputCalendarEntry;

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

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertCalendarEntryAsync(inputCalendarEntry))
            .ReturnsAsync(expectedCalendarEntry);

            // when
            CalendarEntry actualCalendarEntry =
                await this.calendarEntryService.AddCalendarEntryAsync(inputCalendarEntry);

            // then
            actualCalendarEntry.Should().BeEquivalentTo(expectedCalendarEntry);

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertCalendarEntryAsync(inputCalendarEntry),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldDeleteCalendarEntryByIdAsync()
        {
            // given
            DateTimeOffset dateTime              = GetRandomDateTime();
            CalendarEntry  randomCalendarEntry   = CreateRandomCalendarEntry(dateTime);
            Guid           inputCalendarEntryId  = randomCalendarEntry.Id;
            CalendarEntry  inputCalendarEntry    = randomCalendarEntry;
            CalendarEntry  storageCalendarEntry  = randomCalendarEntry;
            CalendarEntry  expectedCalendarEntry = randomCalendarEntry;

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectCalendarEntryByIdAsync(inputCalendarEntryId))
            .ReturnsAsync(inputCalendarEntry);

            this.storageBrokerMock.Setup(broker =>
                                         broker.DeleteCalendarEntryAsync(inputCalendarEntry))
            .ReturnsAsync(storageCalendarEntry);

            // when
            CalendarEntry actualCalendarEntry =
                await this.calendarEntryService.RemoveCalendarEntryByIdAsync(inputCalendarEntryId);

            // then
            actualCalendarEntry.Should().BeEquivalentTo(expectedCalendarEntry);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectCalendarEntryByIdAsync(inputCalendarEntryId),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.DeleteCalendarEntryAsync(inputCalendarEntry),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }