コード例 #1
0
        public void Test_Get_By_Id()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            var options = new DbContextOptionsBuilder <EmployeeContext>().UseSqlite(connection).Options;

            using (var context = new EmployeeContext(options))
            {
                context.Database.EnsureCreated();
            }

            using (var context = new EmployeeContext(options))
            {
                context.Employees.Add(new Employee {
                    Id = 1, FirstName = "John", LastName = "Doe", Address = "123 Street", HomePhone = "111-111-1111", CellPhone = "222-222-2222"
                });
                context.SaveChanges();
            }

            using (var context = new EmployeeContext(options))
            {
                var provider = new EmployeeProvider(context);
                var employee = provider.Get(1);

                Assert.AreEqual("John", employee.FirstName);
            }
        }
コード例 #2
0
        /// <summary>
        /// Saves the employee.
        /// </summary>
        /// <param name="profile">The profile.</param>
        /// <returns>a Task</returns>
        private async Task SaveEmployee(IEmployeeProfile profile)
        {
            var tempEmployee = new EmployeeProfile
            {
                FirstName    = profile.FirstName,
                LastName     = profile.LastName,
                Salary       = profile.Salary,
                HoursPerDay  = profile.HoursPerDay,
                DaysPerWeek  = profile.DaysPerWeek,
                WeeksPerYear = profile.WeeksPerYear
            };

            var validator = new EmployeeProfileValidator();
            var results   = validator.Validate(tempEmployee);

            if (results.IsValid)
            {
                SaveButtonEnabled = false;
                var saveSuccess = await EmployeeProvider.AddEmployee(tempEmployee);

                //TODO move to resources
                Message           = saveSuccess == 1 ? "Employee details saved" : "Unable able to save employee details";
                SaveButtonEnabled = true;
            }
            else
            {
                foreach (var error in results.Errors)
                {
                    Message = error.ErrorMessage;
                }
            }
            Message = string.Empty;
        }
コード例 #3
0
        public async Task Edit_WhenAuthenticatedRequestReceivedWithInvalidModelState_ThenRedirectToReadViewActionReturned()
        {
            var employee       = EmployeeProvider.GetOnePreEditTestEmployee();
            var editedEmployee = EmployeeProvider.GetOnePostEditTestEmployee();

            _mockAuthService
            .Setup(a => a.IsAuthenticated(_user))
            .Returns(true);
            _mockRepository
            .Setup(r => r.EditAsync(employee.Id, editedEmployee))
            .ReturnsAsync(editedEmployee);

            var controller = new EmployeeController(_mockAuthService.Object, _mockRepository.Object, _mockService.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = _user
                }
            };

            controller.ModelState.AddModelError("Forename", "Forename maximum length reached");
            var actual = await controller.Edit(employee.Id, editedEmployee) as RedirectToActionResult;

            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.ActionName == "Read");
        }
コード例 #4
0
        public async Task GetOne_WhenAuthenticatedUserRequestsPage_ThenADetailViewResultWithEmployeesReturned()
        {
            _mockAuthService
            .Setup(a => a.IsAuthenticated(_user))
            .Returns(true);
            _mockRepository
            .Setup(r => r.ReadAsync(1))
            .ReturnsAsync(EmployeeProvider.GetOneTestEmployee());

            var controller = new EmployeeController(_mockAuthService.Object, _mockRepository.Object, _mockService.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = _user
                }
            };

            var actual = await controller.GetOne(1) as ViewResult;

            var actualModel = actual.Model as Employee;

            Assert.IsNotNull(actual);
            Assert.IsInstanceOf <ViewResult>(actual);
            Assert.That("Detail", Is.EqualTo(actual.ViewName));
            Assert.That("Alice", Is.EqualTo(actualModel.Forename));
        }
コード例 #5
0
        public async Task <BaseResponse> InsertEmployeeAsync()
        {
            EmployeeProvider e = new EmployeeProvider();

            e.ClientProxyObj = new DocumentDB();

            Employee emp = new Employee();

            emp.Id             = 40;
            emp.IsActive       = true;
            emp.IsGroup        = false;
            emp.FirstName      = "Kishan";
            emp.LastName       = "Tanpure";
            emp.EmailAddress   = "*****@*****.**";
            emp.Rating         = true;
            emp.Role           = EmployeeRoles.Employee;
            emp.UserName       = "******";
            emp.OTP            = "123";
            emp.EmployeeDevice = new List <Device>
            {
                new Device()
                {
                    OTP              = 123,
                    DeviceNumber     = "14",
                    Id               = 1,
                    MobileNumber     = "8446247702",
                    IsLandingEnabled = true,
                    Type             = DeviceType.iOS
                }
            };

            return(await e.InsertEmployee(emp));
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: vladbilyk/aspose-test-task
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments <Options>(args).WithParsed(o =>
            {
                Console.WriteLine("Running salary calculator with parameters:");
                Console.WriteLine($"File path: {o.FilePath}");
                Console.WriteLine($"Salary date: {o.SalaryDate.ToShortDateString()}");
                Console.WriteLine("---------------------------------------------------------");

                if (!File.Exists(o.FilePath))
                {
                    Console.WriteLine($"File {o.FilePath} is missing.");
                    return;
                }

                var provider  = new EmployeeProvider(new FileJsonEmployeeDataProvider(o.FilePath));
                var employees = provider.GetEmployees();
                Console.WriteLine($"Company with {employees.Count()} persons was loaded:");

                foreach (var person in employees)
                {
                    Console.WriteLine($"{person.Name} with salary {person.GetSalaryByDate(o.SalaryDate)}");
                }

                Console.WriteLine($"Total: {employees.Sum(e => e.GetSalaryByDate(o.SalaryDate))}");
            });
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: sambc49/AsyncCsvReader
        private async static Task <Employee> GetEmployeeFromService(string id)
        {
            var employeeProvider = new EmployeeProvider();
            var result           = employeeProvider.GetEmployee(id);

            return(await result);
        }
コード例 #8
0
        public async Task Create_WhenAuthenticatedRequestReceivedWithInvalidModelState_ThenRedirectToCreateViewActionReturned()
        {
            var employee = EmployeeProvider.GetOnePreCreationTestEmployee();

            _mockAuthService
            .Setup(a => a.IsAuthenticated(_user))
            .Returns(true);
            _mockRepository
            .Setup(r => r.AddAsync(employee))
            .ReturnsAsync(EmployeeProvider.GetOnePostCreationTestEmployee());

            var controller = new EmployeeController(_mockAuthService.Object, _mockRepository.Object, _mockService.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = _user
                }
            };

            controller.ModelState.AddModelError("Forename", "Forename maximum length reached");
            var actual = await controller.Create(employee) as ViewResult;

            Assert.IsNotNull(actual);
            Assert.IsInstanceOf <ViewResult>(actual);
            Assert.That("Create", Is.EqualTo(actual.ViewName));
        }
コード例 #9
0
        public async Task Create_WhenAuthenticatedRequestReceived_ThenRedirectToReadViewActionReturned()
        {
            var employee = EmployeeProvider.GetOnePreCreationTestEmployee();

            _mockAuthService
            .Setup(a => a.IsAuthenticated(_user))
            .Returns(true);
            _mockRepository
            .Setup(r => r.AddAsync(employee))
            .ReturnsAsync(EmployeeProvider.GetOnePostCreationTestEmployee());

            var controller = new EmployeeController(_mockAuthService.Object, _mockRepository.Object, _mockService.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = _user
                }
            };

            var actual = await controller.Create(employee) as RedirectToActionResult;

            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.ActionName == "Read");
            Assert.IsTrue(actual.ControllerName == "Employee");
        }
コード例 #10
0
        public string UpdateDetails(int id, Employees obj)
        {
            EmployeeProvider employee = new EmployeeProvider();
            var name = employee.GetEmployees.Where(i => i.Id == id).FirstOrDefault();

            name.Name = obj.Name;
            employee.SaveChanges();
            return("updated");
        }
コード例 #11
0
        public string UpdateDetails(int id)
        {
            EmployeeProvider employee = new EmployeeProvider();
            var name = employee.GetEmployees.Where(i => i.Id == id).FirstOrDefault();

            employee.GetEmployees.Remove(name);
            employee.SaveChanges();
            return("Deleted");
        }
コード例 #12
0
        public void Find_MethodNotCalled()
        {
            ISource source = Substitute.For <ISource>();

            var provider = new EmployeeProvider(source);

            Assert.That(() => { provider.Find(null); }, Throws.ArgumentNullException);
            source.DidNotReceiveWithAnyArgs().FindByName(null);
        }
コード例 #13
0
        public void Find_MethodNotCalled()
        {
            Mock <ISource> source = new Mock <ISource>();

            var provider = new EmployeeProvider(source.Object);

            Assert.That(() => { provider.Find(null); }, Throws.ArgumentNullException);
            source.Verify(s => s.FindByName(null), Times.Never);
        }
コード例 #14
0
        public async Task <BaseResponse> GetEmployeeAsync(string id)
        {
            EmployeeProvider e = new EmployeeProvider();

            e.ClientProxyObj = new DocumentDB();
            var vurn = await e.GetEmployee(id);

            return(vurn);
        }
コード例 #15
0
 public AdministrationController(
     CustomerProvider CustomerProvider,
     EmployeeProvider EmployeeProvider,
     AddressProvider AddressProvider,
     EmailProvider EmailProvider,
     PhoneProvider PhoneProvider) : base(AddressProvider, EmailProvider, PhoneProvider)
 {
     this.CustomerProvider = CustomerProvider;
     this.EmployeeProvider = EmployeeProvider;
 }
コード例 #16
0
        public void GetAllEmployees()
        {
            RepositoryMock   respository = new RepositoryMock();
            EmployeeProvider provider    = new EmployeeProvider(respository);

            List <Employee> employeeList = provider.GetAllEmployees(null);

            Assert.IsTrue(employeeList.Count > 0);
            Assert.IsTrue(employeeList.Count == 3);
        }
コード例 #17
0
        public void Delete_EnsureThatMethodIsCalled()
        {
            ISource source = Substitute.For <ISource>();

            var provider = new EmployeeProvider(source);

            provider.Delete(5);

            source.Received(1).Delete(5);
        }
コード例 #18
0
        public void Delete_EnsureThatMethodIsCalled()
        {
            Mock <ISource> source = new Mock <ISource>();

            var provider = new EmployeeProvider(source.Object);

            provider.Delete(5);

            source.Verify(s => s.Delete(5), Times.Once);
        }
コード例 #19
0
        public ReviewerVM(ITransition transition)
        {
            var provider = EmployeeProvider.GetEmployeeProvider();
            var user     = provider.GetUserData(transition.ApproverID);

            EmployeeNumber = user.Username;
            Name           = user.DisplayName;
            Position       = user.JobTitle;
            Date           = (transition.ApproverDecision == DecisionType.Approved) ? transition.AcknowledgementDate?.ToString("dd/MM/yyyy") : null;
            Signature      = (transition.ApproverDecision == DecisionType.Approved) ? user.ElectronicSignature : null;
        }
コード例 #20
0
        protected EmployeeProvider GetEmployeeProvider()
        {
            EmployeeProvider employee = null;

            if (employee == null)
            {
                return(new EmployeeProvider());
            }

            return(employee);
        }
コード例 #21
0
        public EmployeeEntity GetEmployee(int id)
        {
            var result = EmployeeProvider.GetEmployee(id);

            if (_lastSavedEmployee != null && id == _lastSavedEmployee.Id)
            {
                result.ExtensionData = _lastSavedEmployee.ExtensionData;
            }

            return(result);
        }
コード例 #22
0
        public void GetAllEmployeesValidateHourlySalary()
        {
            RepositoryMock   respository = new RepositoryMock();
            EmployeeProvider provider    = new EmployeeProvider(respository);

            //id 2 is an employee with this salary type
            List <Employee> employeeList = provider.GetAllEmployees(2);

            Assert.IsTrue(employeeList.Count > 0);
            Assert.IsTrue(employeeList.Count == 1);
            Assert.IsTrue(employeeList.First().Salary == 64800);
        }
コード例 #23
0
        public void Get_ReturnsSpecifiedEmployee()
        {
            ISource source = Substitute.For <ISource>();

            source.GetById(5).Returns(new Employee(5, "NSubstitute"));

            var provider = new EmployeeProvider(source);
            var employee = provider.Get(5);

            Assert.That(employee, Is.Not.Null);
            Assert.That(employee.Id, Is.EqualTo(5));
            Assert.That(employee.Name, Is.EqualTo("NSubsitute"));
        }
コード例 #24
0
        public HttpResponseMessage deleteorModifyEmployee(EmployeeDeleteRequestModel employeeDeleteRequest)
        {
            EmployeeProvider employeeProvider = new EmployeeProvider();
            ErrorModel       errorModel       = null;
            var deleteorModifyEmployee        = employeeProvider.deleteorModifyEmployee(employeeDeleteRequest, out errorModel);

            APIResponseModel aPIResponseModel = new APIResponseModel();

            aPIResponseModel.Response = deleteorModifyEmployee;
            aPIResponseModel.Error    = errorModel;

            return(Request.CreateResponse(HttpStatusCode.OK, aPIResponseModel));
        }
コード例 #25
0
        public HttpResponseMessage registerEmployee(RegisterEmployeeRequestModel employeeRequestModel)
        {
            EmployeeProvider employeeProvider = new EmployeeProvider();
            ErrorModel       errorModel       = null;
            var userRegisterResponse          = employeeProvider.registerEmployee(employeeRequestModel, out errorModel);

            APIResponseModel aPIResponseModel = new APIResponseModel();

            aPIResponseModel.Response = userRegisterResponse;
            aPIResponseModel.Error    = errorModel;

            return(Request.CreateResponse(HttpStatusCode.OK, aPIResponseModel));
        }
コード例 #26
0
        public void Get_ReturnsSpecifiedEmployee()
        {
            Mock <ISource> source = new Mock <ISource>();

            source.Setup(s => s.GetById(5)).Returns(new Employee(5, "Moq"));

            var provider = new EmployeeProvider(source.Object);
            var employee = provider.Get(5);

            Assert.That(employee, Is.Not.Null);
            Assert.That(employee.Id, Is.EqualTo(5));
            Assert.That(employee.Name, Is.EqualTo("Moq"));
        }
コード例 #27
0
        public static void SendReminders(this ICanAction approvalFlow)
        {
            var application = approvalFlow.GetMetadata("app");
            var empProvider = EmployeeProvider.GetEmployeeProvider();
            var portalPath  = ConfigurationManager.AppSettings["PortalPath"];

            var    obj              = (IApprovalFlow <ITransition>)approvalFlow;
            var    path             = approvalFlow.GetMetadata("path");
            string longDescription  = approvalFlow.GetMetadata("longDescription");
            string shortDescription = approvalFlow.GetMetadata("shortDescription");
            string objID            = approvalFlow.GetMetadata("id");

            var transitionsAwaitingDecision = obj.Transitions.Where(t => t.ApproverDecision == DecisionType.AwaitingDecision && t.RequestedDate < DateTime.Now.AddDays(-2)).OrderByDescending(t => t.Order).ToList();

            foreach (var transition in transitionsAwaitingDecision)
            {
                Employee u1 = empProvider.GetUserData(transition.ApproverID);
                Employee u2 = empProvider.GetUserData(transition.RequesterID);

                string msg = "Your Action is Required. Requested by " + u2.DisplayName + ".";
                if (transition.RequesterComments != null)
                {
                    msg = msg + "<br/><br/><p>Comments : <br/>" + transition.RequesterComments + "</p>";
                }

                var mail = new EmailMessage()
                {
                    Sender        = "*****@*****.**",
                    RecipientName = u1.DisplayName,
                    Recipient     = u1.Mail,
                    CCRecipients  = new string[] { u2.Mail },
                    Subject       = "(" + application + ") " + shortDescription + ", Reminder Notification: " + transition.ApproverDecision.GetDisplay(),
                    Body          = msg + "<br/><a href=\"" + portalPath + path + "/Index/" + obj.GetID() + "\"/>Open Document</a><br/><br/>"
                };

                if (!(transition.ApproverID == "52980409" && path == "/Procurement/Requisitions"))
                {
                    using (var email = new EmailHandler(mail))
                        email.Send();

                    RegisterAlert.ForApp(application)
                    .WithCategory("Approval Reminder")
                    .ByUser(transition.RequesterID)
                    .ToTargetEmployees(new string[] { transition.ApproverID })
                    .IsMajor()
                    .WithMessage(shortDescription + ", Approval Notification: " + transition.ApproverDecision.GetDisplay() + ". Requested by " + u2.DisplayName + ".")
                    .WithURL(portalPath + path + "/Index/" + objID)
                    .PushAlert();
                }
            }
        }
コード例 #28
0
        public async Task GetOne_WhenUnAuthenticatedRequestReceived_ThenRedirectToSignInViewActionReturned()
        {
            _mockAuthService
            .Setup(a => a.IsAuthenticated(_user))
            .Returns(false);
            _mockRepository
            .Setup(r => r.ReadAsync(1))
            .ReturnsAsync(EmployeeProvider.GetOneTestEmployee());

            var controller = new EmployeeController(_mockAuthService.Object, _mockRepository.Object, _mockService.Object);

            var actual = await controller.GetOne(1) as RedirectToActionResult;

            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.ActionName == "SignIn");
            Assert.IsTrue(actual.ControllerName == "Authentication");
        }
コード例 #29
0
        public void SetUp()
        {
            _employeeStub = new List <Employee>();
            _employeeStub.Add(EmployeeProvider.GetOneTestEmployee());
            _employeesStub = EmployeeProvider.GetAllTestEmployees();

            _mockAuthService = new Mock <IAuthenticationService>();
            _mockRepository  = new Mock <IEmployeeRepository>();
            _mockService     = new Mock <IPaginationService>();

            _mockService
            .Setup(s => s.Page)
            .Returns(1);
            _mockService
            .Setup(s => s.PageSize)
            .Returns(10);

            _user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, "Alice"),
                new Claim(ClaimTypes.NameIdentifier, "1"),
            }, "mock"));
        }
コード例 #30
0
        public List <Employees> GetEmployeeDetails()
        {
            EmployeeProvider employeepro = new EmployeeProvider();

            return(employeepro.GetEmployees.ToList());
        }