public async Task EditVacationPage(UserAndOrganizationDto userAndOrg, VacationPageDto vacationPageDto)
        {
            var vacationPage = await _vacationPagesDbSet.FirstOrDefaultAsync(page => page.OrganizationId == userAndOrg.OrganizationId);

            if (vacationPage == null)
            {
                _vacationPagesDbSet.Add(new VacationPage
                {
                    Content        = vacationPageDto.Content,
                    OrganizationId = userAndOrg.OrganizationId,
                });

                await _uow.SaveChangesAsync();

                return;
            }

            vacationPage.Content = vacationPageDto.Content;

            await _uow.SaveChangesAsync();
        }
Esempio n. 2
0
        public async Task Should_Create_New_VacationPage_If_It_Does_Not_Exist()
        {
            // Arrange
            var vacationPageToAdd = new VacationPageDto
            {
                Content = "test"
            };

            var organizationId = int.MaxValue;

            var userAndOrg = new UserAndOrganizationDto
            {
                UserId         = Guid.NewGuid().ToString(),
                OrganizationId = organizationId
            };

            // Act
            await _vacationPageService.EditVacationPage(userAndOrg, vacationPageToAdd);

            // Assert
            _vacationPagesDbSet.Received().Add(Arg.Any <VacationPage>());
        }
Esempio n. 3
0
        public async Task Should_Update_VacationPage()
        {
            // Arrange
            var vacationPageUpdate = new VacationPageDto
            {
                Content = "update content"
            };

            var userAndOrg = new UserAndOrganizationDto
            {
                UserId         = Guid.NewGuid().ToString(),
                OrganizationId = TestConstants.DefaultOrganizationId
            };

            // Act
            await _vacationPageService.EditVacationPage(userAndOrg, vacationPageUpdate);

            var actualUpdatedVacation = await _vacationPagesDbSet.FirstAsync(page => page.OrganizationId == TestConstants.DefaultOrganizationId);

            // Assert
            Assert.AreEqual(TestConstants.DefaultOrganizationId, actualUpdatedVacation.OrganizationId);
            Assert.AreEqual(vacationPageUpdate.Content, actualUpdatedVacation.Content);
        }