Ejemplo n.º 1
0
        public async Task ShouldGetAllCalendarEntryAttachmentsAsync()
        {
            // given
            var randomCalendarEntryAttachments = new List <CalendarEntryAttachment>();

            for (var i = 0; i <= GetRandomNumber(); i++)
            {
                CalendarEntryAttachment randomCalendarEntryAttachment = await PostCalendarEntryAttachmentAsync();

                randomCalendarEntryAttachments.Add(randomCalendarEntryAttachment);
            }

            List <CalendarEntryAttachment> inputCalendarEntryAttachments    = randomCalendarEntryAttachments;
            List <CalendarEntryAttachment> expectedCalendarEntryAttachments = inputCalendarEntryAttachments;

            // when
            List <CalendarEntryAttachment> actualCalendarEntryAttachments =
                await this.otripleSApiBroker.GetAllCalendarEntryAttachmentsAsync();

            // then
            foreach (CalendarEntryAttachment expectedCalendarEntryAttachment in expectedCalendarEntryAttachments)
            {
                CalendarEntryAttachment actualCalendarEntryAttachment =
                    actualCalendarEntryAttachments.Single(studentAttachment =>
                                                          studentAttachment.CalendarEntryId == expectedCalendarEntryAttachment.CalendarEntryId);

                actualCalendarEntryAttachment.Should().BeEquivalentTo(expectedCalendarEntryAttachment);

                await DeleteCalendarEntryAttachmentAsync(actualCalendarEntryAttachment);
            }
        }
        public async Task ShouldThrowDependencyExceptionOnAddWhenDbExceptionOccursAndLogItAsync()
        {
            // given
            CalendarEntryAttachment someCalendarEntryAttachment = CreateRandomCalendarEntryAttachment();
            var databaseUpdateException = new DbUpdateException();

            var expectedCalendarEntryAttachmentDependencyException =
                new CalendarEntryAttachmentDependencyException(databaseUpdateException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertCalendarEntryAttachmentAsync(It.IsAny <CalendarEntryAttachment>()))
            .ThrowsAsync(databaseUpdateException);

            // when
            ValueTask <CalendarEntryAttachment> addCalendarEntryAttachmentTask =
                this.calendarEntryAttachmentService.AddCalendarEntryAttachmentAsync(someCalendarEntryAttachment);

            // then
            await Assert.ThrowsAsync <CalendarEntryAttachmentDependencyException>(() =>
                                                                                  addCalendarEntryAttachmentTask.AsTask());

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertCalendarEntryAttachmentAsync(It.IsAny <CalendarEntryAttachment>()),
                                          Times.Once);

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedCalendarEntryAttachmentDependencyException))),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnAddWhenCalendarEntryAttachmentIsNullAndLogItAsync()
        {
            // given
            CalendarEntryAttachment nullCalendarEntryAttachment = default;
            var nullCalendarEntryAttachmentException            = new NullCalendarEntryAttachmentException();

            var expectedCalendarEntryAttachmentValidationException =
                new CalendarEntryAttachmentValidationException(nullCalendarEntryAttachmentException);

            // when
            ValueTask <CalendarEntryAttachment> addCalendarEntryAttachmentTask =
                this.calendarEntryAttachmentService.AddCalendarEntryAttachmentAsync(nullCalendarEntryAttachment);

            // then
            await Assert.ThrowsAsync <CalendarEntryAttachmentValidationException>(() =>
                                                                                  addCalendarEntryAttachmentTask.AsTask());

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(expectedCalendarEntryAttachmentValidationException))),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertCalendarEntryAttachmentAsync(It.IsAny <CalendarEntryAttachment>()),
                                          Times.Never);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Ejemplo n.º 4
0
        public ValueTask <CalendarEntryAttachment> AddCalendarEntryAttachmentAsync(
            CalendarEntryAttachment calendarEntryAttachment) => TryCatch(async() =>
        {
            ValidateCalendarEntryAttachmentOnCreate(calendarEntryAttachment);

            return(await this.storageBroker.InsertCalendarEntryAttachmentAsync(calendarEntryAttachment));
        });
        public async void ShouldThrowValidationExceptionOnAddWhenAttachmentIdIsInvalidAndLogItAsync()
        {
            // given
            CalendarEntryAttachment randomCalendarEntryAttachment = CreateRandomCalendarEntryAttachment();
            CalendarEntryAttachment inputCalendarEntryAttachment  = randomCalendarEntryAttachment;

            inputCalendarEntryAttachment.AttachmentId = default;

            var invalidCalendarEntryAttachmentInputException = new InvalidCalendarEntryAttachmentException(
                parameterName: nameof(CalendarEntryAttachment.AttachmentId),
                parameterValue: inputCalendarEntryAttachment.AttachmentId);

            var expectedCalendarEntryAttachmentValidationException =
                new CalendarEntryAttachmentValidationException(invalidCalendarEntryAttachmentInputException);

            // when
            ValueTask <CalendarEntryAttachment> addCalendarEntryAttachmentTask =
                this.calendarEntryAttachmentService.AddCalendarEntryAttachmentAsync(inputCalendarEntryAttachment);

            // then
            await Assert.ThrowsAsync <CalendarEntryAttachmentValidationException>(() =>
                                                                                  addCalendarEntryAttachmentTask.AsTask());

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(expectedCalendarEntryAttachmentValidationException))),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertCalendarEntryAttachmentAsync(It.IsAny <CalendarEntryAttachment>()),
                                          Times.Never);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldAddCalendarEntryAttachmentAsync()
        {
            // given
            CalendarEntryAttachment randomCalendarEntryAttachment   = CreateRandomCalendarEntryAttachment();
            CalendarEntryAttachment inputCalendarEntryAttachment    = randomCalendarEntryAttachment;
            CalendarEntryAttachment storageCalendarEntryAttachment  = randomCalendarEntryAttachment;
            CalendarEntryAttachment expectedCalendarEntryAttachment = storageCalendarEntryAttachment;

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertCalendarEntryAttachmentAsync(inputCalendarEntryAttachment))
            .ReturnsAsync(storageCalendarEntryAttachment);

            // when
            CalendarEntryAttachment actualCalendarEntryAttachment =
                await this.calendarEntryAttachmentService.AddCalendarEntryAttachmentAsync(inputCalendarEntryAttachment);

            // then
            actualCalendarEntryAttachment.Should().BeEquivalentTo(expectedCalendarEntryAttachment);

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertCalendarEntryAttachmentAsync(inputCalendarEntryAttachment),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldRetrieveCalendarEntryAttachmentById()
        {
            // given
            CalendarEntryAttachment randomCalendarEntryAttachment   = CreateRandomCalendarEntryAttachment();
            CalendarEntryAttachment storageCalendarEntryAttachment  = randomCalendarEntryAttachment;
            CalendarEntryAttachment expectedCalendarEntryAttachment = storageCalendarEntryAttachment;

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectCalendarEntryAttachmentByIdAsync(
                                             randomCalendarEntryAttachment.CalendarEntryId, randomCalendarEntryAttachment.AttachmentId))
            .ReturnsAsync(randomCalendarEntryAttachment);

            // when
            CalendarEntryAttachment actualCalendarEntryAttachment = await
                                                                    this.calendarEntryAttachmentService.RetrieveCalendarEntryAttachmentByIdAsync(
                randomCalendarEntryAttachment.CalendarEntryId, randomCalendarEntryAttachment.AttachmentId);

            // then
            actualCalendarEntryAttachment.Should().BeEquivalentTo(expectedCalendarEntryAttachment);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectCalendarEntryAttachmentByIdAsync(
                                              randomCalendarEntryAttachment.CalendarEntryId, randomCalendarEntryAttachment.AttachmentId),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
 private static void ValidateCalendarEntryAttachmentIsNull(CalendarEntryAttachment calendarEntryAttachment)
 {
     if (calendarEntryAttachment is null)
     {
         throw new NullCalendarEntryAttachmentException();
     }
 }
Ejemplo n.º 9
0
        private static void ValidateCalendarEntryAttachmentOnCreate(CalendarEntryAttachment calendarEntryAttachment)
        {
            ValidateCalendarEntryAttachmentIsNull(calendarEntryAttachment);

            ValidateCalendarEntryAttachmentIds(
                calendarEntryAttachment.CalendarEntryId,
                calendarEntryAttachment.AttachmentId);
        }
        public ValueTask <CalendarEntryAttachment> RemoveCalendarEntryAttachmentByIdAsync(
            Guid calendarEntryId, Guid attachmentId) => TryCatch(async() =>
        {
            ValidateCalendarEntryAttachmentIds(calendarEntryId, attachmentId);
            CalendarEntryAttachment maybeCalendarEntryAttachment = await this.storageBroker.SelectCalendarEntryAttachmentByIdAsync(calendarEntryId, attachmentId);
            ValidateStorageCalendarEntryAttachment(maybeCalendarEntryAttachment, calendarEntryId, attachmentId);

            return(await this.storageBroker.DeleteCalendarEntryAttachmentAsync(maybeCalendarEntryAttachment));
        });
 private static void ValidateStorageCalendarEntryAttachment(
     CalendarEntryAttachment storageCalendarEntryAttachment,
     Guid calendarEntryId, Guid attachmentId)
 {
     if (storageCalendarEntryAttachment is null)
     {
         throw new NotFoundCalendarEntryAttachmentException(calendarEntryId, attachmentId);
     }
 }
        public async ValueTask <CalendarEntryAttachment> InsertCalendarEntryAttachmentAsync(
            CalendarEntryAttachment calendarEntryAttachment)
        {
            EntityEntry <CalendarEntryAttachment> calendarEntryAttachmentEntityEntry =
                await this.CalendarEntriesAttachments.AddAsync(calendarEntryAttachment);

            await this.SaveChangesAsync();

            return(calendarEntryAttachmentEntityEntry.Entity);
        }
        public async ValueTask <CalendarEntryAttachment> DeleteCalendarEntryAttachmentAsync(
            CalendarEntryAttachment calendarEntryAttachment)
        {
            EntityEntry <CalendarEntryAttachment> calendarEntryAttachmentEntityEntry =
                this.CalendarEntriesAttachments.Remove(calendarEntryAttachment);

            await this.SaveChangesAsync();

            return(calendarEntryAttachmentEntityEntry.Entity);
        }
        private static void ValidateCalendarEntryAttachmentOnAdd(CalendarEntryAttachment calendarEntryAttachment)
        {
            ValidateCalendarEntryAttachmentIsNull(calendarEntryAttachment);

            Validate(
                (Rule: IsInvalid(calendarEntryAttachment.AttachmentId),
                 Parameter: nameof(CalendarEntryAttachment.AttachmentId)),

                (Rule: IsInvalid(calendarEntryAttachment.CalendarEntryId),
                 Parameter: nameof(CalendarEntryAttachment.CalendarEntryId)));
        }
        public async ValueTask <CalendarEntryAttachment> DeleteCalendarEntryAttachmentAsync(
            CalendarEntryAttachment calendarEntryAttachment)
        {
            using var broker = new StorageBroker(this.configuration);

            EntityEntry <CalendarEntryAttachment> calendarEntryAttachmentEntityEntry =
                broker.CalendarEntriesAttachments.Remove(entity: calendarEntryAttachment);

            await broker.SaveChangesAsync();

            return(calendarEntryAttachmentEntityEntry.Entity);
        }
        ShouldThrowValidationExceptionOnRemoveWhenStorageCalendarEntryAttachmentIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset          randomDateTime = GetRandomDateTime();
            CalendarEntryAttachment randomCalendarEntryAttachment = CreateRandomCalendarEntryAttachment(randomDateTime);
            Guid inputAttachmentId    = randomCalendarEntryAttachment.AttachmentId;
            Guid inputCalendarEntryId = randomCalendarEntryAttachment.CalendarEntryId;
            CalendarEntryAttachment nullStorageCalendarEntryAttachment = null;

            var notFoundCalendarEntryAttachmentException =
                new NotFoundCalendarEntryAttachmentException(inputCalendarEntryId, inputAttachmentId);

            var expectedCalendarEntryValidationException =
                new CalendarEntryAttachmentValidationException(notFoundCalendarEntryAttachmentException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectCalendarEntryAttachmentByIdAsync(inputCalendarEntryId, inputAttachmentId))
            .ReturnsAsync(nullStorageCalendarEntryAttachment);

            // when
            ValueTask <CalendarEntryAttachment> removeCalendarEntryAttachmentTask =
                this.calendarEntryAttachmentService.RemoveCalendarEntryAttachmentByIdAsync(inputCalendarEntryId, inputAttachmentId);

            // then
            await Assert.ThrowsAsync <CalendarEntryAttachmentValidationException>(() =>
                                                                                  removeCalendarEntryAttachmentTask.AsTask());

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectCalendarEntryAttachmentByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()),
                                          Times.Once);

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedCalendarEntryValidationException))),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.DeleteCalendarEntryAttachmentAsync(It.IsAny <CalendarEntryAttachment>()),
                                          Times.Never);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldRemoveCalendarEntryAttachmentAsync()
        {
            // given
            var  randomCalendarEntryId = Guid.NewGuid();
            var  randomAttachmentId    = Guid.NewGuid();
            Guid inputCalendarEntryId  = randomCalendarEntryId;
            Guid inputAttachmentId     = randomAttachmentId;
            CalendarEntryAttachment randomCalendarEntryAttachment = CreateRandomCalendarEntryAttachment();

            randomCalendarEntryAttachment.CalendarEntryId = inputCalendarEntryId;
            randomCalendarEntryAttachment.AttachmentId    = inputAttachmentId;
            CalendarEntryAttachment storageCalendarEntryAttachment  = randomCalendarEntryAttachment;
            CalendarEntryAttachment expectedCalendarEntryAttachment = storageCalendarEntryAttachment;

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectCalendarEntryAttachmentByIdAsync(inputCalendarEntryId, inputAttachmentId))
            .ReturnsAsync(storageCalendarEntryAttachment);

            this.storageBrokerMock.Setup(broker =>
                                         broker.DeleteCalendarEntryAttachmentAsync(storageCalendarEntryAttachment))
            .ReturnsAsync(expectedCalendarEntryAttachment);

            // when
            CalendarEntryAttachment actualCalendarEntryAttachment =
                await this.calendarEntryAttachmentService.RemoveCalendarEntryAttachmentByIdAsync(
                    inputCalendarEntryId, inputAttachmentId);

            // then
            actualCalendarEntryAttachment.Should().BeEquivalentTo(expectedCalendarEntryAttachment);

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.DeleteCalendarEntryAttachmentAsync(storageCalendarEntryAttachment),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnAddWhenReferneceExceptionAndLogItAsync()
        {
            // given
            CalendarEntryAttachment randomCalendarEntryAttachment = CreateRandomCalendarEntryAttachment();
            CalendarEntryAttachment someCalendarEntryAttachment   = randomCalendarEntryAttachment;
            string randomMessage    = GetRandomMessage();
            string exceptionMessage = randomMessage;
            var    foreignKeyConstraintConflictException = new ForeignKeyConstraintConflictException(exceptionMessage);

            var invalidCalendarEntryAttachmentReferenceException =
                new InvalidCalendarEntryAttachmentReferenceException(foreignKeyConstraintConflictException);

            var expectedCalendarEntryAttachmentValidationException =
                new CalendarEntryAttachmentValidationException(invalidCalendarEntryAttachmentReferenceException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertCalendarEntryAttachmentAsync(someCalendarEntryAttachment))
            .ThrowsAsync(foreignKeyConstraintConflictException);

            // when
            ValueTask <CalendarEntryAttachment> addCalendarEntryAttachmentTask =
                this.calendarEntryAttachmentService.AddCalendarEntryAttachmentAsync(someCalendarEntryAttachment);

            // then
            await Assert.ThrowsAsync <CalendarEntryAttachmentValidationException>(() =>
                                                                                  addCalendarEntryAttachmentTask.AsTask());

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertCalendarEntryAttachmentAsync(It.IsAny <CalendarEntryAttachment>()),
                                          Times.Once);

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedCalendarEntryAttachmentValidationException))),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnAddWhenCalendarEntryAttachmentAlreadyExistsAndLogItAsync()
        {
            // given
            CalendarEntryAttachment randomCalendarEntryAttachment        = CreateRandomCalendarEntryAttachment();
            CalendarEntryAttachment alreadyExistsCalendarEntryAttachment = randomCalendarEntryAttachment;
            string randomMessage         = GetRandomMessage();
            string exceptionMessage      = randomMessage;
            var    duplicateKeyException = new DuplicateKeyException(exceptionMessage);

            var alreadyExistsCalendarEntryAttachmentException =
                new AlreadyExistsCalendarEntryAttachmentException(duplicateKeyException);

            var expectedCalendarEntryAttachmentValidationException =
                new CalendarEntryAttachmentValidationException(alreadyExistsCalendarEntryAttachmentException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertCalendarEntryAttachmentAsync(alreadyExistsCalendarEntryAttachment))
            .ThrowsAsync(duplicateKeyException);

            // when
            ValueTask <CalendarEntryAttachment> addCalendarEntryAttachmentTask =
                this.calendarEntryAttachmentService.AddCalendarEntryAttachmentAsync(alreadyExistsCalendarEntryAttachment);

            // then
            await Assert.ThrowsAsync <CalendarEntryAttachmentValidationException>(() =>
                                                                                  addCalendarEntryAttachmentTask.AsTask());

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertCalendarEntryAttachmentAsync(It.IsAny <CalendarEntryAttachment>()),
                                          Times.Once);

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedCalendarEntryAttachmentValidationException))),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Ejemplo n.º 20
0
        public async Task ShouldPostCalendarEntryAttachmentAsync()
        {
            // given
            CalendarEntryAttachment randomCalendarEntryAttachment = await CreateRandomCalendarEntryAttachment();

            CalendarEntryAttachment inputCalendarEntryAttachment    = randomCalendarEntryAttachment;
            CalendarEntryAttachment expectedCalendarEntryAttachment = inputCalendarEntryAttachment;

            // when
            CalendarEntryAttachment actualCalendarEntryAttachment =
                await this.otripleSApiBroker.PostCalendarEntryAttachmentAsync(inputCalendarEntryAttachment);

            CalendarEntryAttachment retrievedCalendarEntryAttachment =
                await this.otripleSApiBroker.GetCalendarEntryAttachmentByIdsAsync(
                    inputCalendarEntryAttachment.CalendarEntryId,
                    inputCalendarEntryAttachment.AttachmentId);

            // then
            actualCalendarEntryAttachment.Should().BeEquivalentTo(expectedCalendarEntryAttachment);
            retrievedCalendarEntryAttachment.Should().BeEquivalentTo(expectedCalendarEntryAttachment);
            await DeleteCalendarEntryAttachmentAsync(actualCalendarEntryAttachment);
        }
        public async void ShouldThrowValidationExceptionOnAddWhenCalendarEntryAttachmentIsInvalidAndLogItAsync()
        {
            // given
            var invalidCalendarEntryAttachment = new CalendarEntryAttachment();
            var invalidCalendarEntryAttachmentInputException = new InvalidCalendarEntryAttachmentException();

            invalidCalendarEntryAttachmentInputException.AddData(
                key: nameof(CalendarEntryAttachment.AttachmentId),
                values: "Id is required");

            invalidCalendarEntryAttachmentInputException.AddData(
                key: nameof(CalendarEntryAttachment.CalendarEntryId),
                values: "Id is required");

            var expectedCalendarEntryAttachmentValidationException =
                new CalendarEntryAttachmentValidationException(invalidCalendarEntryAttachmentInputException);

            // when
            ValueTask <CalendarEntryAttachment> addCalendarEntryAttachmentTask =
                this.calendarEntryAttachmentService.AddCalendarEntryAttachmentAsync(invalidCalendarEntryAttachment);

            // then
            await Assert.ThrowsAsync <CalendarEntryAttachmentValidationException>(() =>
                                                                                  addCalendarEntryAttachmentTask.AsTask());

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameValidationExceptionAs(
                                                                    expectedCalendarEntryAttachmentValidationException))),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertCalendarEntryAttachmentAsync(It.IsAny <CalendarEntryAttachment>()),
                                          Times.Never);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Ejemplo n.º 22
0
        public async Task ShouldDeleteCalendarEntryAttachmentAsync()
        {
            // given
            CalendarEntryAttachment randomCalendarEntryAttachment = await PostCalendarEntryAttachmentAsync();

            CalendarEntryAttachment inputCalendarEntryAttachment    = randomCalendarEntryAttachment;
            CalendarEntryAttachment expectedCalendarEntryAttachment = inputCalendarEntryAttachment;

            // when
            CalendarEntryAttachment deletedCalendarEntryAttachment =
                await DeleteCalendarEntryAttachmentAsync(inputCalendarEntryAttachment);

            ValueTask <CalendarEntryAttachment> getCalendarEntryAttachmentByIdTask =
                this.otripleSApiBroker.GetCalendarEntryAttachmentByIdsAsync(
                    inputCalendarEntryAttachment.CalendarEntryId,
                    inputCalendarEntryAttachment.AttachmentId);

            // then
            deletedCalendarEntryAttachment.Should().BeEquivalentTo(expectedCalendarEntryAttachment);

            await Assert.ThrowsAsync <HttpResponseNotFoundException>(() =>
                                                                     getCalendarEntryAttachmentByIdTask.AsTask());
        }
Ejemplo n.º 23
0
 public async ValueTask <CalendarEntryAttachment> PostCalendarEntryAttachmentAsync(CalendarEntryAttachment calendarEntryAttachment) =>
 await this.apiFactoryClient.PostContentAsync(CalendarEntryAttachmentsRelativeUrl, calendarEntryAttachment);
        private void btnSave_Click(object sender, EventArgs e)
        {
            Building selectedBuilding = null;

            if (String.IsNullOrWhiteSpace(cbEvent.Text) ||
                String.IsNullOrWhiteSpace(tbVenue.Text)
                )
            {
                Controller.HandleError("Please complete all fields", "Validation Error");
                return;
            }

            if (rbFinancial.Checked)
            {
                selectedBuilding = (cbBuilding.SelectedItem as Building);
                if (selectedBuilding == null)
                {
                    Controller.HandleError("Building required", "Validation Error");
                    return;
                }
            }
            var minTime = new TimeSpan(05, 00, 00);
            var maxTime = new TimeSpan(23, 59, 00);

            if (dtpEventTime.Value.TimeOfDay < minTime || dtpEventTime.Value.TimeOfDay > maxTime)
            {
                Controller.HandleError("Event time must be > 05:00 and < 23:59", "Validation Error");
                return;
            }


            if (dtpEventToTime.Value.TimeOfDay < minTime || dtpEventToTime.Value.TimeOfDay > maxTime)
            {
                Controller.HandleError("Event time must be > 05:00 and < 23:59", "Validation Error");
                return;
            }

            if (dtpEventDate.Value.Date < DateTime.Today)
            {
                Controller.HandleError("Cannot schedule an event in the past.", "Validation Error");
                return;
            }

            if (!string.IsNullOrWhiteSpace(tbBCC.Text))
            {
                if (!tbBCC.Text.Contains("@") || !tbBCC.Text.Contains("."))
                {
                    Controller.HandleError("BCC not a valid email address.", "Validation Error");
                    return;
                }
            }

            DateTime fromDate = dtpEventDate.Value.Date + dtpEventTime.Value.TimeOfDay;
            DateTime toDate   = dtpEventToDate.Value.Date + dtpEventToTime.Value.TimeOfDay;

            if (fromDate >= toDate)
            {
                Controller.HandleError("To Date/Time cannot be more than the From Date/Time.", "Validation Error");
                return;
            }

            using (var context = SqlDataHandler.GetDataContext())
            {
                BuildingCalendarEntry editItem = null;
                if (_Item == null)
                {
                    editItem = new BuildingCalendarEntry();
                    context.BuildingCalendarEntrySet.Add(editItem);
                }
                else
                {
                    editItem = context.BuildingCalendarEntrySet.Include(a => a.UserInvites).Single(a => a.id == _Item.id);
                    foreach (var itm in editItem.UserInvites.ToList())
                    {
                        context.CalendarUserInviteSet.Remove(itm);
                    }
                }

                if (selectedBuilding != null)
                {
                    editItem.BuildingId = selectedBuilding.ID;
                }
                else
                {
                    editItem.BuildingId = null;
                }
                if (rbStaff.Checked)
                {
                    editItem.CalendarEntryType = CalendarEntryType.Staff;
                }
                else
                {
                    editItem.CalendarEntryType = CalendarEntryType.Financial;
                }

                if (rbFinancial.Checked)
                {
                    var pm = (from b in context.tblBuildings
                              join u in context.tblUsers on b.pm equals u.email
                              where b.id == editItem.BuildingId
                              select u).SingleOrDefault();

                    if (pm != null)
                    {
                        editItem.UserId = pm.id;
                    }
                    else if (editItem.id == 0)
                    {
                        editItem.UserId = Controller.user.id;
                    }
                    editItem.UserInvites = new List <CalendarUserInvite>();
                }
                else
                {
                    editItem.UserId      = Controller.user.id;
                    editItem.UserInvites = new List <CalendarUserInvite>();
                    foreach (var checkedItem in cbUserInvites.CheckedItems)
                    {
                        var usr = (tblUser)checkedItem;
                        editItem.UserInvites.Add(new CalendarUserInvite()
                        {
                            CalendarEntry = editItem,
                            UserId        = usr.id
                        });
                    }
                }

                editItem.EntryDate       = fromDate;
                editItem.EventToDate     = toDate;
                editItem.Event           = cbEvent.Text;
                editItem.Venue           = tbVenue.Text;
                editItem.NotifyTrustees  = cbNotifyTrustees.Checked;
                editItem.InviteSubject   = tbSubject.Text;
                editItem.BCCEmailAddress = tbBCC.Text;
                editItem.InviteBody      = tbBodyContent.Text;

                if (cbRoom.SelectedItem != null)
                {
                    editItem.MeetingRoomId = (cbRoom.SelectedItem as IdValue).Id;
                }
                else
                {
                    editItem.MeetingRoomId = null;
                }

                if (CheckDoubleBooking(context, editItem))
                {
                    return;
                }

                //check for attachments
                if (_FileToLoad != null)
                {
                    CalendarEntryAttachment fileItem = null;

                    if (editItem.id > 0)
                    {
                        fileItem = context.CalendarEntryAttachmentSet.Where(a => a.BuildingCalendarEntryId == editItem.id).FirstOrDefault();
                    }

                    if (fileItem == null)
                    {
                        fileItem = new CalendarEntryAttachment()
                        {
                            CalendarEntry = editItem
                        };
                        context.CalendarEntryAttachmentSet.Add(fileItem);
                    }

                    fileItem.FileData = _FileToLoad;
                    fileItem.FileName = tbAttachment.Text;
                }

                context.SaveChanges();
            }

            LoadGrid();
        }