public ActionResult DeleteConfirmed(string id)
 {
     _userId          = User.Identity.GetUserId();
     _employerService = new EmployerService(_userId);
     _employerService.DeleteEmployer(id);
     return(RedirectToAction("Index"));
 }
        public void CheckEmployerIdAfterAdd()
        {
            //Arrange
            NewEmployerVm employerToAdd = new NewEmployerVm()
            {
                Id   = 6,
                Name = "test",
                NIP  = "Unit"
            };

            Employer employer = new Employer()
            {
                Id   = 6,
                Name = "test",
                NIP  = "Unit"
            };

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            var mock = new Mock <IEmployerRepository>();

            mock.Setup(s => s.AddEmployer(employer)).Returns(employer.Id);

            var manager = new EmployerService(mapper, mock.Object);

            //Act
            var result = manager.AddEmployer(employerToAdd);

            //Assert
            result.Should().Equals(employer.Id);
        }
        public When_Employer_Service_Is_Called_To_Handle_Valid_Employer_Created_Event_For_New_Employer()
        {
            var config = new MapperConfiguration(c => c.AddMaps(typeof(EmployerMapper).Assembly));
            var mapper = new Mapper(config);

            _employerRepository = Substitute.For <IRepository <Domain.Models.Employer> >();
            var opportunityRepository = Substitute.For <IOpportunityRepository>();

            _employerRepository.GetSingleOrDefaultAsync(Arg.Any <Expression <Func <Domain.Models.Employer, bool> > >())
            .Returns((Domain.Models.Employer)null);

            _messageQueueService = Substitute.For <IMessageQueueService>();

            var employerService = new EmployerService(_employerRepository, opportunityRepository, mapper, new CrmEmployerEventDataValidator(),
                                                      _messageQueueService);

            _employerEventBase = new CrmEmployerEventBaseBuilder()
                                 .WithValidAupaStatus().Build();

            var data = JsonConvert.SerializeObject(_employerEventBase, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore
            });

            employerService.HandleEmployerCreatedAsync(data).GetAwaiter().GetResult();
        }
Exemplo n.º 4
0
        private EmployerService CreateEmployerService()
        {
            var userId          = User.Identity.GetUserId();
            var employerService = new EmployerService(userId);

            return(employerService);
        }
Exemplo n.º 5
0
        public void DeletedEmployerShoundNotExistInDatabase()
        {
            //Arrange
            NewEmployerVm employerToAdd = new NewEmployerVm()
            {
                Id   = 1,
                Name = "test",
                NIP  = "Unit"
            };

            var options = new DbContextOptionsBuilder <Context>()
                          .UseInMemoryDatabase("UsersDirectoryMVC")
                          .Options;

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            using (var context = new Context(options))
            {
                //Act
                var employerService = new EmployerService(mapper, new EmployerRepository(context));
                var result          = employerService.AddEmployer(employerToAdd);
                employerService.DeleteEmployer(1);
                var deletedEmployer = employerService.GetEmployerDetails(1);

                //Assert
                deletedEmployer.Should().BeNull();
            }
        }
        public void CheckEmployerToEditDetailsAreEqualLikeModel()
        {
            //Arrange
            Employer employer = new Employer()
            {
                Id   = 6,
                Name = "test",
                NIP  = "unit",
            };

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            var mock = new Mock <IEmployerRepository>();

            mock.Setup(s => s.GetEmployer(6)).Returns(employer);

            var manager = new EmployerService(mapper, mock.Object);

            //Act
            var result = manager.GetEmployerForEdit(6);

            //Assert
            result.Should().NotBeNull();
            result.Id.Should().Equals(employer.Id);
            employer.Id = 7;
            result.Id.Should().Equals(employer.Id);
            result.Name.Should().Equals(employer.Name);
            result.NIP.Should().Equals(employer.NIP);
        }
Exemplo n.º 7
0
        public EmployerController(EmployerService employerService)
        {
            this.employerService = employerService;

            UserManager = new ApplicationUserManager(new UserStore <ApplicationUser>(HttpContext.Current.GetOwinContext()
                                                                                     .Get <ApplicationIdentityContext>().Users));
        }
Exemplo n.º 8
0
        public void CheckEmployerIfExistAfterAdd()
        {
            //Arrange
            NewEmployerVm employerToAdd = new NewEmployerVm()
            {
                Id   = 1,
                Name = "test",
                NIP  = "Unit"
            };

            var options = new DbContextOptionsBuilder <Context>()
                          .UseInMemoryDatabase("UsersDirectoryMVC")
                          .Options;

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            using (var context = new Context(options))
            {
                //Act
                var employerService = new EmployerService(mapper, new EmployerRepository(context));
                var result          = employerService.AddEmployer(employerToAdd);

                //Assert
                context.Employers.FirstOrDefaultAsync(e => e.Id == result).Should().NotBeNull();
            }
        }
Exemplo n.º 9
0
        public void GetByIdShouldReturnEmployerModel()
        {
            string name = "Employer Name";
            string eik  = "0000000000";

            var expected = new Employer {
                Id = 1, Name = name, Eik = eik
            };
            var repository = new Mock <IDeletableEntityRepository <Employer> >();

            repository.Setup(posts => posts.All())
            .Returns(new List <Employer>
            {
                new Employer()
                {
                    Id = 1, Name = name, Eik = eik
                },
            }.AsQueryable());

            var service = new EmployerService(repository.Object, null);
            var result  = service.GetById(1);

            Assert.True(
                expected.Id == result.Id &&
                expected.Name == result.Name &&
                expected.Eik == result.Eik);
            repository.Verify(x => x.All(), Times.Once);
        }
Exemplo n.º 10
0
        // api/Employer/GetEmployerList
        public IHttpActionResult Get()
        {
            EmployerService employerService = CreateEmployerService();
            var             employers       = employerService.GetEmployers();

            return(Ok(employers));
        }
Exemplo n.º 11
0
        public void SaveEmployer_updates_timestamp()
        {
            //
            //Arrange
            _repo   = new Mock <IEmployerRepository>();
            _uow    = new Mock <IUnitOfWork>();
            _woServ = new Mock <IWorkOrderService>();
            _map    = new Mock <IMapper>();

            var _e = (Employer)Records.employer.Clone();

            string user = "******";

            _e.datecreated = DateTime.MinValue;
            _e.dateupdated = DateTime.MinValue;
            var _serv = new EmployerService(_repo.Object, _woServ.Object, _uow.Object, _map.Object);

            //
            //Act
            _serv.Save(_e, user);
            //
            //Assert
            Assert.IsTrue(_e.updatedby == user);
            Assert.IsTrue(_e.dateupdated > DateTime.MinValue);
        }
Exemplo n.º 12
0
        public void DeleteEmployer()
        {
            //
            //Arrange
            _repo   = new Mock <IEmployerRepository>();
            _uow    = new Mock <IUnitOfWork>();
            _woServ = new Mock <IWorkOrderService>();
            _map    = new Mock <IMapper>();

            var _e = (Employer)Records.employer.Clone();

            string   user = "******";
            int      id   = 1;
            Employer dp   = new Employer();

            _repo.Setup(r => r.Delete(It.IsAny <Employer>())).Callback((Employer p) => { dp = p; });
            _repo.Setup(r => r.GetById(id)).Returns(_e);
            var _serv = new EmployerService(_repo.Object, _woServ.Object, _uow.Object, _map.Object);

            //
            //Act
            _serv.Delete(id, user);
            //
            //Assert
            Assert.AreEqual(dp, _e);
        }
Exemplo n.º 13
0
        public void CreateEmployer_returns_employer()
        {
            //
            //Arrange
            _repo   = new Mock <IEmployerRepository>();
            _uow    = new Mock <IUnitOfWork>();
            _woServ = new Mock <IWorkOrderService>();
            _map    = new Mock <IMapper>();
            string user = "******";
            var    _e   = (Employer)Records.employer.Clone();

            _e.datecreated = DateTime.MinValue;
            _e.dateupdated = DateTime.MinValue;
            _repo.Setup(r => r.Add(_e)).Returns(_e);
            var _serv = new EmployerService(_repo.Object, _woServ.Object, _uow.Object, _map.Object);
            //
            //Act
            var result = _serv.Create(_e, user);

            //
            //Assert
            Assert.IsInstanceOfType(result, typeof(Employer));
            Assert.IsTrue(result.createdby == user);
            Assert.IsTrue(result.updatedby == user);
            Assert.IsTrue(result.datecreated > DateTime.MinValue);
            Assert.IsTrue(result.dateupdated > DateTime.MinValue);
        }
Exemplo n.º 14
0
 public EmployerServiceUnitTests()
 {
     _repo = new Mock<IEmployerRepository>();
     _uow = new Mock<IUnitOfWork>();
     _woServ = new Mock<IWorkOrderService>();
     _serv = new EmployerService(_repo.Object, _woServ.Object, _uow.Object);
 }
Exemplo n.º 15
0
 public EmployerTests()
 {
     _repo   = new Mock <IEmployerRepository>();
     _uow    = new Mock <IUnitOfWork>();
     _woServ = new Mock <IWorkOrderService>();
     _map    = new Mock <IMapper>();
     _serv   = new EmployerService(_repo.Object, _woServ.Object, _uow.Object, _map.Object);
 }
        public async Task WhenInvalidEmployerAccountId_ThenReturnEmptyString()
        {
            _mockAccountApiClient.Setup(x => x.GetAccount(It.IsAny <long>())).Throws(new Exception());
            var sut    = new EmployerService(_mockAccountApiClient.Object);
            var result = await sut.GetEmployerName(123);

            result.Should().Be((string.Empty, string.Empty));
        }
Exemplo n.º 17
0
 public CustomerController(CustomerService svc, TransactionsService accountsService, DocumentController documentController, EmployerService employerService)
 {
     _customerService    = svc;
     _documentController = documentController;
     _employerService    = employerService;
     InitialisePaymentSourcesViewBag(accountsService);
     InitialiseEmployersViewBag(employerService);
 }
 async void ProcessServicesSelectedCommand(EmployerService vals)
 {
     if (vals != null)
     {
         NavigationParameters paramx = new NavigationParameters();
         paramx.Add("Data", vals);
         await _nav.NavigateAsync(nameof(ServiceDetailsPage), paramx, false, true);
     }
 }
Exemplo n.º 19
0
        public void ValidatesEmployerTest()
        {
            // Arrange
            var service = new EmployerService(_employerRepository);

            // Act
            var employerObj = service.ValidateEmployer(_employerToTest);

            // Assert
            Assert.IsTrue(employerObj);
        }
Exemplo n.º 20
0
        public void ValidatesEmployerExistTest()
        {
            // Arrange
            var service = new EmployerService(_employerRepository);

            // Act
            var employerObj = service.FindExistingEmployer(_employerToTest);

            // Assert
            Assert.IsNotNull(employerObj);
        }
Exemplo n.º 21
0
        public ActionResult Create(EmployerCreate employer)
        {
            if (ModelState.IsValid)
            {
                _userId          = User.Identity.GetUserId();
                _employerService = new EmployerService(_userId);
                _employerService.CreateEmployer(employer);
                return(RedirectToAction("Index"));
            }

            return(View(employer));
        }
        private static EmployerFacade CreateFacade(
            Mock <QueryObjectBase <EmployerDto, Employer, EmployerFilterDto, IQuery <Employer> > > employerQueryMock,
            Mock <IEmployerRepository> employerRepositoryMock)
        {
            var mockManager = new FacadeMockManager();
            var uowMock     = FacadeMockManager.ConfigureUowMock();
            var mapper      = FacadeMockManager.ConfigureRealMapper();
            var service     = new EmployerService(mapper, employerRepositoryMock.Object, employerQueryMock.Object, new AuthenticationService());
            var facade      = new EmployerFacade(uowMock.Object, service);

            return(facade);
        }
Exemplo n.º 23
0
        // api/Employer/GetEmployerById
        public IHttpActionResult Get(string id)
        {
            EmployerService employerService = CreateEmployerService();
            var             employer        = employerService.GetEmployerById(id);

            if (employer == null)
            {
                return(NotFound());
            }

            return(Ok(employer));
        }
Exemplo n.º 24
0
        public void ValidatesEmployer_DoesNotExistTest()
        {
            // Arrange
            var service = new EmployerService(_employerRepository);

            _employerToTest.LegalName = "Some Other Name";
            // Act
            var employerObj = service.FindExistingEmployer(_employerToTest);

            // Assert
            Assert.IsNull(employerObj);
        }
        public void OnNavigatingTo(NavigationParameters parameters)
        {
            // set data from params..
            var data = parameters.Where(x => x.Key == "Data").FirstOrDefault();
            var obj  = data.Value;

            if (obj != null && obj is EmployerService)
            {
                // yah we have what we need so continue..
                ServiceDetails = obj as EmployerService;
            }
        }
        private static EmployerFacade CreateFacade(QueryResultDto <EmployerDto, EmployerFilterDto> expectedQueryResult)
        {
            var mockManager    = new FacadeMockManager();
            var uowMock        = FacadeMockManager.ConfigureUowMock();
            var mapper         = FacadeMockManager.ConfigureRealMapper();
            var repositoryMock = new Mock <IEmployerRepository>(MockBehavior.Loose);
            var queryMock      =
                mockManager.ConfigureQueryObjectMock <EmployerDto, Employer, EmployerFilterDto>(expectedQueryResult);
            var customerService = new EmployerService(mapper, repositoryMock.Object, queryMock.Object, new AuthenticationService());
            var customerFacade  = new EmployerFacade(uowMock.Object, customerService);

            return(customerFacade);
        }
        public async Task WhenInvalidEmployerAccountId_ThenReturnEmployerName()
        {
            var expectedName      = "employer name";
            var expectedAccountId = "expectedid";

            _mockAccountApiClient.Setup(x => x.GetAccount(It.IsAny <long>())).ReturnsAsync(new AccountDetailViewModel {
                DasAccountName = expectedName, PublicHashedAccountId = expectedAccountId
            });
            var sut    = new EmployerService(_mockAccountApiClient.Object);
            var result = await sut.GetEmployerName(123);

            result.Should().Be((expectedName, expectedAccountId));
        }
Exemplo n.º 28
0
        public void ValidatesEmployer_Require_LegalName_TestFail()
        {
            // Arrange
            var service = new EmployerService(_employerRepository);

            _employerToTest.LegalName = null;

            // Act
            var employerObj = service.ValidateEmployer(_employerToTest);

            // Assert
            Assert.IsFalse(employerObj);
        }
Exemplo n.º 29
0
        public void ValidatesEmployer_Require_County_TestFail()
        {
            // Arrange
            var service = new EmployerService(_employerRepository);

            _employerToTest.PhysicalAddress.County = null;

            // Act
            var employerObj = service.ValidateEmployer(_employerToTest);

            // Assert
            Assert.IsFalse(employerObj);
        }
        public When_EmployerService_Is_Called_To_Get_Opportunity_Employer_Owner_Null()
        {
            var employerRepository = Substitute.For <IRepository <Domain.Models.Employer> >();

            _opportunityRepository = Substitute.For <IOpportunityRepository>();

            _opportunityRepository.GetFirstOrDefaultAsync(Arg.Any <Expression <Func <Domain.Models.Opportunity, bool> > >())
            .Returns((Domain.Models.Opportunity)null);

            var employerService = new EmployerService(employerRepository, _opportunityRepository, Substitute.For <IMapper>(), Substitute.For <IValidator <CrmEmployerEventBase> >(),
                                                      Substitute.For <IMessageQueueService>());

            _result = employerService.GetEmployerOpportunityOwnerAsync(new Guid("11111111-1111-1111-1111-111111111111")).GetAwaiter().GetResult();
        }
Exemplo n.º 31
0
        public static IEmployerService <Employer> GetEmployers()
        {
            IEmployerService <Employer> serviceObj = null;

            switch (sectionHandler.ConnectionStringName)
            {
            case DataBaseType.SKILLSMART_MONGO_DB: serviceObj = new EmployerService(DatabaseFactory.CreateMongoDatabase());
                break;

            default: serviceObj = new EmployerService(DatabaseFactory.CreateMongoDatabase());
                break;
            }
            return(serviceObj);
        }
Exemplo n.º 32
0
 public static IEmployerService<Employer> GetEmployers()
 {
     IEmployerService<Employer> serviceObj = null;
     switch (sectionHandler.ConnectionStringName)
     {
         case DataBaseType.SKILLSMART_MONGO_DB: serviceObj = new EmployerService(DatabaseFactory.CreateMongoDatabase());
             break;
         default: serviceObj = new EmployerService(DatabaseFactory.CreateMongoDatabase());
             break;
     }
     return serviceObj;
 }
Exemplo n.º 33
0
        public void EmployerService_DeleteEmployer()
        {
            //
            //Arrange
            _repo = new Mock<IEmployerRepository>();
            _uow = new Mock<IUnitOfWork>();
            _woServ = new Mock<IWorkOrderService>();
            var _e = (Employer)Records.employer.Clone();

            string user = "******";
            int id = 1;
            Employer dp = new Employer();
            _repo.Setup(r => r.Delete(It.IsAny<Employer>())).Callback((Employer p) => { dp = p; });
            _repo.Setup(r => r.GetById(id)).Returns(_e);
            var _serv = new EmployerService(_repo.Object, _woServ.Object, _uow.Object);
            //
            //Act
            _serv.Delete(id, user);
            //
            //Assert
            Assert.AreEqual(dp, _e);
        }
Exemplo n.º 34
0
        public void EmployerService_SaveEmployer_updates_timestamp()
        {
            //
            //Arrange
            _repo = new Mock<IEmployerRepository>();
            _uow = new Mock<IUnitOfWork>();
            _woServ = new Mock<IWorkOrderService>();
            var _e = (Employer)Records.employer.Clone();

            string user = "******";
            _e.datecreated = DateTime.MinValue;
            _e.dateupdated = DateTime.MinValue;
            var _serv = new EmployerService(_repo.Object, _woServ.Object, _uow.Object);
            //
            //Act
            _serv.Save(_e, user);
            //
            //Assert
            Assert.IsTrue(_e.Updatedby == user);
            Assert.IsTrue(_e.dateupdated > DateTime.MinValue);
        }
Exemplo n.º 35
0
 public void EmployerService_CreateEmployer_returns_employer()
 {
     //
     //Arrange
     _repo = new Mock<IEmployerRepository>();
     _uow = new Mock<IUnitOfWork>();
     _woServ = new Mock<IWorkOrderService>();
     string user = "******";
     var _e = (Employer)Records.employer.Clone();
     _e.datecreated = DateTime.MinValue;
     _e.dateupdated = DateTime.MinValue;
     _repo.Setup(r => r.Add(_e)).Returns(_e);
     var _serv = new EmployerService(_repo.Object, _woServ.Object, _uow.Object);
     //
     //Act
     var result = _serv.Create(_e, user);
     //
     //Assert
     Assert.IsInstanceOfType(result, typeof(Employer));
     Assert.IsTrue(result.Createdby == user);
     Assert.IsTrue(result.Updatedby == user);
     Assert.IsTrue(result.datecreated > DateTime.MinValue);
     Assert.IsTrue(result.dateupdated > DateTime.MinValue);
 }