コード例 #1
0
        public void VacationTime_AddNewVacationTime()
        {
            using (var db = new AppDbContext(Utilities.TestDbContextOptions()))
            {
                // Arrange
                DateTime dateFrom = new DateTime(2021, 12, 01);
                DateTime dateTo   = new DateTime(2021, 12, 31);

                var vacationRepo          = new EfCoreVacationRepo(db);
                var vacationTimeViewModel = new VacationTimeViewModel();
                var vacationTime          = new VacationTime()
                {
                    Id        = Guid.NewGuid(),
                    Person    = "master",
                    DateFrom  = dateFrom.ToString(CultureInfo.InvariantCulture),
                    DateTo    = dateTo.ToString(CultureInfo.InvariantCulture),
                    Reason    = "Testing vacation",
                    CreatedAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.CurrentCulture),
                    UpdatedAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.CurrentCulture),
                    TotalDays = vacationTimeViewModel.CalculateDays(dateFrom, dateTo).ToString(CultureInfo.InvariantCulture) + " dni"
                };

                // Act
                vacationRepo.Add(vacationTime);

                // Assert
                Assert.AreEqual((dateTo - dateFrom).TotalDays + " dni", vacationRepo.Get(vacationTime.Id).Result.TotalDays);
                Assert.AreEqual(vacationTime.Reason, vacationRepo.Get(vacationTime.Id).Result.Reason);
                Assert.IsNotNull(vacationRepo.Get(vacationTime.Id).Result.Person);
            }
        }
コード例 #2
0
        public async Task <IActionResult> OnPost()
        {
            var userName = User.Identity.Name;
            var toAdd    = new VacationTime()
            {
                Id        = Guid.NewGuid(),
                DateFrom  = VacationTimeModel.DateFrom.ToString("yyyy-MM-dd"),
                DateTo    = VacationTimeModel.DateTo.ToString("yyyy-MM-dd"),
                Reason    = VacationTimeModel.Reason,
                CreatedAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.CurrentCulture),
                Person    = userName,
                TotalDays = VacationTimeModel.CalculateDays(VacationTimeModel.DateFrom, VacationTimeModel.DateTo).ToString() + " dni"
            };

            await _efCoreVacation.Add(toAdd);

            SuccessCreationMessage = "Dodano urlop";
            return(RedirectToPage("/TimeManagement/Time/Urlopy"));
        }