Esempio n. 1
0
        public async Task GetCurrentUserByUsername_WithDummyData_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "UserService GetCurrentUserByUsername() method does not work properly.";

            var context = MdmsDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            _userService = new UserService(new FakeUserManager(), context);

            MDMSUserServiceModel actualResults = await _userService.GetCurrentUserByUsername("Pesho");

            MDMSUserServiceModel expectedResults = context.Users.SingleOrDefault(x => x.UserName == "Pesho").To <MDMSUserServiceModel>();

            Assert.True(actualResults.Id == expectedResults.Id, errorMessagePrefix + " " + "Id is not returned properly.");
            Assert.True(actualResults.Name == expectedResults.Name, errorMessagePrefix + " " + "Name is not returned properly.");
            Assert.True(actualResults.FirstName == expectedResults.FirstName, errorMessagePrefix + " " + "FirstName is not returned properly.");
            Assert.True(actualResults.LastName == expectedResults.LastName, errorMessagePrefix + " " + "LastName is not returned properly.");
            Assert.True(actualResults.Email == expectedResults.Email, errorMessagePrefix + " " + "Email is not returned properly.");
            Assert.True(actualResults.AdditionalOnHourPayment == expectedResults.AdditionalOnHourPayment, errorMessagePrefix + " " + "AdditionalOnHourPayment is not returned properly.");
            Assert.True(actualResults.BaseSalary == expectedResults.BaseSalary, errorMessagePrefix + " " + "BaseSalary is not returned properly.");
            Assert.True(actualResults.IsDeleted == expectedResults.IsDeleted, errorMessagePrefix + " " + "IsDeleted is not returned properly.");
            Assert.True(actualResults.IsRepairing == expectedResults.IsRepairing, errorMessagePrefix + " " + "IsRepairing is not returned properly.");
            Assert.True(actualResults.IsAuthorized == expectedResults.IsAuthorized, errorMessagePrefix + " " + "IsAuthorized is not returned properly.");
        }
        public async Task <bool> EditPayment(MDMSUserServiceModel serviceModel)
        {
            var user = await _context.Users.FindAsync(serviceModel.Id);

            user.BaseSalary = serviceModel.BaseSalary;
            user.AdditionalOnHourPayment = serviceModel.AdditionalOnHourPayment;
            _context.Update(user);
            var result = await _context.SaveChangesAsync();

            return(result > 0);
        }
Esempio n. 3
0
        public async Task EditPayment_WithWrongId_ShouldFailToAddSalary()
        {
            var context = MdmsDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            _userService = new UserService(new FakeUserManager(), context);

            MDMSUserServiceModel user = await _userService.GetCurrentUserByUsername("Pesho");

            user.Id = "NoId";
            user.AdditionalOnHourPayment = 60;
            user.BaseSalary = 4000;

            await Assert.ThrowsAsync <NullReferenceException>(() => _userService.EditPayment(user));
        }
Esempio n. 4
0
        public async Task EditPayment_WithCorrectData_ShouldSuccessfullyEditPayment()
        {
            string errorMessagePrefix = "UserService EditPayment() method does not work properly.";

            var context = MdmsDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            _userService = new UserService(new FakeUserManager(), context);
            MDMSUserServiceModel user = await _userService.GetCurrentUserByUsername("Pesho");

            user.AdditionalOnHourPayment = 60;
            user.BaseSalary = 4000;

            bool actualResult = await _userService.EditPayment(user);

            Assert.True(actualResult, errorMessagePrefix);
        }
Esempio n. 5
0
        public async Task <IActionResult> OnGetAsync(string returnUrl = null)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(LocalRedirect("/"));
            }

            MDMSUserServiceModel user = _userService.GetAllUsers()
                                        .Include(x => x.Salaries)
                                        .Include(x => x.ExternalRepairs)
                                        .Include(x => x.InternalRepairs)
                                        .SingleOrDefault(x => x.Id == _userManager.GetUserId(User)).To <MDMSUserServiceModel>();
            var user1 = await Task.Run((() => _userManager.GetUserAsync(User).Result.To <MDMSUserServiceModel>()));

            FirstName  = user.FirstName;
            LastName   = user.LastName;
            BaseSalary = user.BaseSalary;
            AdditionalOnHourPayment = user.AdditionalOnHourPayment;
            IsAuthorized            = user.IsAuthorized;

            foreach (var salary in user.Salaries)
            {
                Salaries.Add(salary.To <MonthlySalaryViewModel>());
            }
            foreach (var intRep in user.InternalRepairs)
            {
                InternalRepairs.Add(intRep.To <InternalRepairViewModel>());
            }
            foreach (var extRep in user.ExternalRepairs)
            {
                ExternalRepairs.Add(extRep.To <ExternalRepairViewModel>());
            }


            returnUrl = returnUrl ?? Url.Content("~/");

            ReturnUrl = returnUrl;

            return(Page());
        }