public void LookupControllerGet() { var ctrl = new LookupsController(new FakeLookupsRepository()); var result = ctrl.Get(); Assert.IsNotNull(result); }
public async Task InsertCompany() { var company = new Company() { Id = Guid.NewGuid(), Name = "Name1" }; var service = new Mock <IDirectoryLookupService>(); var result = new Result() { Success = true }; Company inserted = null; service.Setup(c => c.InsertCompany(It.IsAny <Company>())) .Callback((Company i) => { inserted = i; }) .ReturnsAsync(result); var controller = new LookupsController(service.Object); var actual = await controller.InsertCompany(company); Assert.Same(company, inserted); var okResult = Assert.IsType <OkObjectResult>(actual); var returnValue = Assert.IsType <Result>(okResult.Value); Assert.Same(result, returnValue); }
public async Task UpdateAdviceService() { var adviceService = new AdviceService() { Id = Guid.NewGuid(), Name = "Name1" }; var service = new Mock <IDirectoryLookupService>(); var result = new Result() { Success = true }; AdviceService updated = null; service.Setup(c => c.UpdateAdviceService(It.IsAny <AdviceService>())) .Callback((AdviceService i) => { updated = i; }) .ReturnsAsync(result); var controller = new LookupsController(service.Object); var actual = await controller.UpdateAdviceService(adviceService.Id.Value, adviceService); Assert.Same(adviceService, updated); var okResult = Assert.IsType <OkObjectResult>(actual); var returnValue = Assert.IsType <Result>(okResult.Value); Assert.Same(result, returnValue); }
public async Task Companies() { var company = new Company() { Id = Guid.NewGuid(), Name = "Name1" }; var companies = new List <Company>() { company }; var service = new Mock <IDirectoryLookupService>(); service.Setup(c => c.GetCompanies()) .ReturnsAsync(companies); var controller = new LookupsController(service.Object); var result = await controller.Companies(); var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <List <Company> >(okResult.Value); Assert.Same(companies, returnValue); }
public async Task GetCommissionTypes() { var type = new CommissionType() { Id = Guid.NewGuid(), Name = "Name1", Code = "Code1", PolicyTypeId = Guid.NewGuid(), CommissionEarningsTypeId = Guid.NewGuid() }; var types = new List <CommissionType>() { type }; var service = new Mock <ICommissionLookupService>(); service.Setup(c => c.GetCommissionTypes()) .ReturnsAsync(types); var controller = new LookupsController(service.Object); var result = await controller.CommissionTypes(); var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <List <CommissionType> >(okResult.Value); Assert.Same(types, returnValue); }
public async Task LicenseCategories() { var licenseCategory = new LicenseCategory() { Id = Guid.NewGuid(), Name = "Name1", Code = "Code1", }; var licenseCategories = new List <LicenseCategory>() { licenseCategory }; var service = new Mock <IDirectoryLookupService>(); service.Setup(c => c.GetLicenseCategories()) .ReturnsAsync(licenseCategories); var controller = new LookupsController(service.Object); var result = await controller.LicenseCategories(); var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <List <LicenseCategory> >(okResult.Value); Assert.Same(licenseCategories, returnValue); }
public async Task PolicyProducts() { var policyProduct = new PolicyProduct() { Id = Guid.NewGuid(), PolicyProductTypeId = Guid.NewGuid(), CompanyId = Guid.NewGuid(), Name = "Name1", Code = "Code1" }; var policyProducts = new List <PolicyProduct>() { policyProduct }; var service = new Mock <IClientLookupService>(); service.Setup(c => c.GetPolicyProducts()) .ReturnsAsync(policyProducts); var controller = new LookupsController(service.Object); var result = await controller.PolicyProducts(); var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <List <PolicyProduct> >(okResult.Value); Assert.Same(policyProducts, returnValue); }
public async Task PolicyTypeCharacteristics() { var policyTypeCharacteristic = new PolicyTypeCharacteristic() { Id = Guid.NewGuid(), PolicyTypeId = Guid.NewGuid(), Name = "Name1", DisplayOrder = 1 }; var policyTypeCharacteristics = new List <PolicyTypeCharacteristic>() { policyTypeCharacteristic }; var service = new Mock <IClientLookupService>(); service.Setup(c => c.GetPolicyTypeCharacteristics()) .ReturnsAsync(policyTypeCharacteristics); var controller = new LookupsController(service.Object); var result = await controller.GetPolicyTypeCharacteristics(); var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <List <PolicyTypeCharacteristic> >(okResult.Value); Assert.Same(policyTypeCharacteristics, returnValue); }
public async Task AdviceServices() { var adviceService = new AdviceService() { Id = Guid.NewGuid(), Name = "Name1" }; var adviceServices = new List <AdviceService>() { adviceService }; var service = new Mock <IDirectoryLookupService>(); service.Setup(c => c.GetAdviceServices()) .ReturnsAsync(adviceServices); var controller = new LookupsController(service.Object); var result = await controller.AdviceServices(); var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <List <AdviceService> >(okResult.Value); Assert.Same(adviceServices, returnValue); }
public async Task All() { var commissionType = new CommissionType() { Id = Guid.NewGuid(), Name = "Name1", Code = "Code1", PolicyTypeId = Guid.NewGuid(), CommissionEarningsTypeId = Guid.NewGuid() }; var commissionEarningsType = new CommissionEarningsType() { Id = Guid.NewGuid(), Name = "Name3" }; var commissionStatementTemplateFieldName = new CommissionStatementTemplateFieldName() { Id = Guid.NewGuid().ToString(), Name = "Name7" }; var commissionTypes = new List <CommissionType>() { commissionType }; var commissionEarningsTypes = new List <CommissionEarningsType>() { commissionEarningsType }; var commissionStatementTemplateFieldNames = new List <CommissionStatementTemplateFieldName>() { commissionStatementTemplateFieldName }; var service = new Mock <ICommissionLookupService>(); service.Setup(c => c.GetCommissionTypes()).ReturnsAsync(commissionTypes); service.Setup(c => c.GetCommissionEarningsTypes()).ReturnsAsync(commissionEarningsTypes); service.Setup(c => c.GetCommissionStatementTemplateFieldNames()).Returns(commissionStatementTemplateFieldNames); var controller = new LookupsController(service.Object); var result = await controller.All(); var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <api.Controllers.Commission.Lookups.Dto.Lookups>(okResult.Value); var all = new api.Controllers.Commission.Lookups.Dto.Lookups() { CommissionTypes = commissionTypes, CommissionEarningsTypes = commissionEarningsTypes, CommissionStatementTemplateFieldNames = commissionStatementTemplateFieldNames, }; Assert.NotStrictEqual(all, returnValue); }
public void PostLookup_ShouldCreateSingleLookup() { Lookup newLookup = new Lookup() { LookupTypeId = 2, LookupValue = "TEST", CreatedBy = "TEST", Created = DateTime.Now, LastModifiedBy = "TEST", LastModified = DateTime.Now, Archived = false }; var lookupsController = new LookupsController { Request = new HttpRequestMessage() { Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } }, Headers = { { "userid", "admin" }, { "lookupTypeId", "2" } }, RequestUri = new Uri("http://localhost/api") }, }; _ = lookupsController.Configuration.Routes.MapHttpRoute( name: "GetLookupById", routeTemplate: "api/Lookups/{id}", defaults: new { id = RouteParameter.Optional }); var postResult = lookupsController.PostLookup(newLookup); var postResponse = postResult.ExecuteAsync(CancellationToken.None).Result; // var getResult = lookupsController.GetLookups(lookupsController.Request); // var getResponse = getResult.ExecuteAsync(CancellationToken.None).Result; Lookup returnLookup = new Lookup(); Assert.IsTrue(postResponse.IsSuccessStatusCode); Assert.IsTrue(postResponse.TryGetContentValue(out returnLookup)); Assert.AreEqual(HttpStatusCode.Created, postResponse.StatusCode); var getResult = lookupsController.GetLookup(returnLookup.Id); var getResponse = getResult.ExecuteAsync(CancellationToken.None).Result; Assert.AreEqual("TEST", returnLookup.LookupValue); var deleteResult = lookupsController.DeleteLookup(returnLookup.Id); var deleteResponse = deleteResult.ExecuteAsync(CancellationToken.None).Result; Assert.IsTrue((deleteResponse.IsSuccessStatusCode)); Assert.AreEqual(HttpStatusCode.OK, deleteResponse.StatusCode); }
public void GetLookupTypes_ReturnsListOfLookupTypesEnumValues() { //Arrange CreateMockedObjects(); var controller = new LookupsController(mockCackedLookupsService.Object, mapper, logFactory); //Act var result = controller.GetLookupTypes(); //Assert var lookupsList = Assert.IsAssignableFrom <IEnumerable <string> >(result); Assert.Equal(lookupsList, Enum.GetNames(typeof(LookupType))); }
public async Task GetAllLookups_ReturnsListOfAllLookups() { //Arrange CreateMockedObjects(); var controller = new LookupsController(mockCackedLookupsService.Object, mapper, logFactory); //Act var result = await controller.GetAllLookups(); //Assert var lookupsList = Assert.IsAssignableFrom <Dictionary <string, IEnumerable <LookupBaseResource> > >(result); Assert.Single(lookupsList["Genders"]); }
public async Task GetRelationsAsync_ReturnsListOfRelations() { //Arrange CreateMockedObjects(); var controller = new LookupsController(mockCackedLookupsService.Object, mapper, logFactory); //Act var result = await controller.GetRelationsAsync(); //Assert var lookupsList = Assert.IsAssignableFrom <IEnumerable <LookupBaseResource> >(result); Assert.Single(lookupsList); }
public void GetLookups_ShouldReturnBadRequestWhenMissingUserIdHeader() { var lookupsController = new LookupsController { Request = new HttpRequestMessage() { Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } }, Headers = {} } }; var getResult = lookupsController.GetLookups(lookupsController.Request); var getResponse = getResult.ExecuteAsync(CancellationToken.None).Result; Assert.IsTrue(!getResponse.IsSuccessStatusCode); Assert.AreEqual(HttpStatusCode.BadRequest, getResponse.StatusCode); }
public void TestInitialize() { _savedLookup = new Lookup(); _fakeLookup = new Lookup { category = "test category", text_EN = "Test EN", text_ES = "Test ES", createdby = "initialization script", updatedby = "initialization script", key = "blah" }; _fakeLookups = new List <Lookup>(); _fakeLookups.Add(_fakeLookup); _fakeLookups.Add(new Lookup() { active = true, category = LCategory.orderstatus, ID = 2, text_EN = "pendiente", text_ES = "pending" }); var mapperConfig = new MapperConfiguration(config => { config.ConfigureApi(); }); _mapper = mapperConfig.CreateMapper(); _lookupServ = new Mock <ILookupService>(); _lookupServ.Setup(s => s.GetMany(It.IsAny <Func <Lookup, bool> >())) .Returns(_fakeLookups.AsQueryable); _lookupServ.Setup(s => s.Get(1)) .Returns(_fakeLookup); _lookupServ.Setup(s => s.Get(1000)) .Returns((Lookup)null); _lookupServ.Setup(s => s.Create(It.IsAny <Lookup>(), It.IsAny <string>())) .Returns(_fakeLookup); _lookupServ.Setup(s => s.Save(It.Is <Lookup>(l => l.key == "blah"), It.IsAny <string>())) .Callback((Lookup l, string s) => _savedLookup = l); _controller = new LookupsController(_lookupServ.Object, _mapper); }
public void GetLookups_ShouldReturnSingleLookup() { var lookupsController = new LookupsController { Request = new HttpRequestMessage() { Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } }, Headers = {} } }; var getResult = lookupsController.GetLookup(1); var getResponse = getResult.ExecuteAsync(CancellationToken.None).Result; Lookup returnLookup = new Lookup(); Assert.IsTrue(getResponse.IsSuccessStatusCode); Assert.AreEqual(HttpStatusCode.OK, getResponse.StatusCode); Assert.IsTrue(getResponse.TryGetContentValue(out returnLookup)); // Did we get a return result? Assert.AreEqual(1, returnLookup.Id); }
public void GetLookups_ShouldReturnNullReturnOnTypeLookups() { var lookupsController = new LookupsController { Request = new HttpRequestMessage() { Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } }, Headers = { { "userid", "admin" }, { "lookupTypeId", "0" } } } }; var getResult = lookupsController.GetLookups(lookupsController.Request); var getResponse = getResult.ExecuteAsync(CancellationToken.None).Result; List <Lookup> returnList = new List <Lookup>(); Assert.IsTrue(getResponse.IsSuccessStatusCode); Assert.AreEqual(HttpStatusCode.OK, getResponse.StatusCode); Assert.IsTrue(getResponse.TryGetContentValue(out returnList)); // Did we get a return result? Assert.AreEqual(0, returnList.Count); }
public async Task UpdatePolicyProduct() { var policyProduct = new PolicyProduct() { Id = Guid.NewGuid(), PolicyProductTypeId = Guid.NewGuid(), CompanyId = Guid.NewGuid(), Name = "Name1", Code = "Code1" }; var service = new Mock <IClientLookupService>(); var result = new Result() { Success = true }; PolicyProduct updated = null; service.Setup(c => c.UpdatePolicyProduct(It.IsAny <PolicyProduct>())) .Callback((PolicyProduct i) => { updated = i; }) .ReturnsAsync(result); var controller = new LookupsController(service.Object); var actual = await controller.UpdatePolicyProduct(policyProduct.Id.Value, policyProduct); Assert.Same(policyProduct, updated); var okResult = Assert.IsType <OkObjectResult>(actual); var returnValue = Assert.IsType <Result>(okResult.Value); Assert.Same(result, returnValue); }
public async Task UpdateCommissionType() { var type = new CommissionType() { Id = Guid.NewGuid(), Name = "Name1", Code = "Code1", PolicyTypeId = Guid.NewGuid(), CommissionEarningsTypeId = Guid.NewGuid() }; var service = new Mock <ICommissionLookupService>(); var result = new Result() { Success = true }; CommissionType updated = null; service.Setup(c => c.UpdateCommissionType(It.IsAny <CommissionType>())) .Callback((CommissionType i) => { updated = i; }) .ReturnsAsync(result); var controller = new LookupsController(service.Object); var actual = await controller.UpdateCommissionType(type.Id.Value, type); Assert.Same(type, updated); var okResult = Assert.IsType <OkObjectResult>(actual); var returnValue = Assert.IsType <Result>(okResult.Value); Assert.Same(result, returnValue); }
public async Task UpdatePolicyTypeCharacteristic() { var policyTypeCharacteristic = new PolicyTypeCharacteristic() { Id = Guid.NewGuid(), PolicyTypeId = Guid.NewGuid(), Name = "Name1", DisplayOrder = 1 }; var service = new Mock <IClientLookupService>(); var result = new Result() { Success = true }; PolicyTypeCharacteristic updated = null; service.Setup(c => c.UpdatePolicyTypeCharacteristic(It.IsAny <PolicyTypeCharacteristic>())) .Callback((PolicyTypeCharacteristic i) => { updated = i; }) .ReturnsAsync(result); var controller = new LookupsController(service.Object); var actual = await controller.UpdatePolicyTypeCharacteristic(policyTypeCharacteristic.Id.Value, policyTypeCharacteristic); Assert.Same(policyTypeCharacteristic, updated); var okResult = Assert.IsType <OkObjectResult>(actual); var returnValue = Assert.IsType <Result>(okResult.Value); Assert.Same(result, returnValue); }
public async Task UpdateLicenseCategory() { var licenseCategory = new LicenseCategory() { Id = Guid.NewGuid(), Name = "Name1", Code = "Code1" }; var service = new Mock <IDirectoryLookupService>(); var result = new Result() { Success = true }; LicenseCategory updated = null; service.Setup(c => c.UpdateLicenseCategory(It.IsAny <LicenseCategory>())) .Callback((LicenseCategory i) => { updated = i; }) .ReturnsAsync(result); var controller = new LookupsController(service.Object); var actual = await controller.UpdateLicenseCategory(licenseCategory.Id.Value, licenseCategory); Assert.Same(licenseCategory, updated); var okResult = Assert.IsType <OkObjectResult>(actual); var returnValue = Assert.IsType <Result>(okResult.Value); Assert.Same(result, returnValue); }
public async Task All() { var policyType = new PolicyType() { Id = Guid.NewGuid(), Name = "Name4", Code = "Code4" }; var policyProductType = new PolicyProductType() { Id = Guid.NewGuid(), Name = "Name4", Code = "Code4", PolicyTypeId = Guid.NewGuid() }; var policyProduct = new PolicyProduct() { Id = Guid.NewGuid(), Name = "Name4", Code = "Code4", PolicyProductTypeId = Guid.NewGuid(), CompanyId = Guid.NewGuid() }; var contactType = new ContactType() { Id = Guid.NewGuid(), Name = "Name5" }; var marritalStatus = new MarritalStatus() { Id = Guid.NewGuid(), Name = "Name6" }; var clientType = new ClientType() { Id = Guid.NewGuid(), Name = "Name8", Code = "Code8" }; var policyTypeCharacteristic = new PolicyTypeCharacteristic() { Id = Guid.NewGuid(), Name = "Name8", DisplayOrder = 1 }; var policyTypes = new List <PolicyType>() { policyType }; var policyProductTypes = new List <PolicyProductType>() { policyProductType }; var policyProducts = new List <PolicyProduct>() { policyProduct }; var clientTypes = new List <ClientType>() { clientType }; var contactTypes = new List <ContactType>() { contactType }; var marritalStatusList = new List <MarritalStatus>() { marritalStatus }; var policyTypeCharacteristicList = new List <PolicyTypeCharacteristic>() { policyTypeCharacteristic }; var service = new Mock <IClientLookupService>(); service.Setup(c => c.GetPolicyTypes()).ReturnsAsync(policyTypes); service.Setup(c => c.GetPolicyProductTypes()).ReturnsAsync(policyProductTypes); service.Setup(c => c.GetPolicyProducts()).ReturnsAsync(policyProducts); service.Setup(c => c.GetContactTypes()).ReturnsAsync(contactTypes); service.Setup(c => c.GetClientTypes()).ReturnsAsync(clientTypes); service.Setup(c => c.GetMarritalStatus()).ReturnsAsync(marritalStatusList); service.Setup(c => c.GetPolicyTypeCharacteristics()).ReturnsAsync(policyTypeCharacteristicList); var controller = new LookupsController(service.Object); var result = await controller.All(); var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <api.Controllers.Client.Lookups.Dto.Lookups>(okResult.Value); var all = new api.Controllers.Client.Lookups.Dto.Lookups() { PolicyTypes = policyTypes, PolicyProductTypes = policyProductTypes, PolicyProducts = policyProducts, ContactTypes = contactTypes, MarritalStatus = marritalStatusList, PolicyTypeCharacteristics = policyTypeCharacteristicList }; Assert.NotStrictEqual(all, returnValue); }
public async Task All() { var company = new Company() { Id = Guid.NewGuid(), Name = "Name2" }; var userType = new UserType() { Id = Guid.NewGuid(), Name = "Name2" }; var adviceScope = new AdviceScope() { Id = Guid.NewGuid(), Name = "Name2" }; var adviceService = new AdviceService() { Id = Guid.NewGuid(), Name = "Name2" }; var licenseCategory = new LicenseCategory() { Id = Guid.NewGuid(), Name = "Name2" }; var companies = new List <Company>() { company }; var userTypes = new List <UserType>() { userType }; var licenseCategories = new List <LicenseCategory>() { licenseCategory }; var adviceServices = new List <AdviceService>() { adviceService }; var adviceScopes = new List <AdviceScope>() { adviceScope }; var service = new Mock <IDirectoryLookupService>(); service.Setup(c => c.GetCompanies()).ReturnsAsync(companies); service.Setup(c => c.GetUserTypes()).ReturnsAsync(userTypes); service.Setup(c => c.GetLicenseCategories()).ReturnsAsync(licenseCategories); service.Setup(c => c.GetAdviceServices()).ReturnsAsync(adviceServices); service.Setup(c => c.GetAdviceScopes()).ReturnsAsync(adviceScopes); var controller = new LookupsController(service.Object); var result = await controller.All(); var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <api.Controllers.Directory.Lookups.Dto.Lookups>(okResult.Value); var all = new api.Controllers.Directory.Lookups.Dto.Lookups() { Companies = companies, UserTypes = userTypes, LicenseCategories = licenseCategories, AdviceScopes = adviceScopes, AdviceServices = adviceServices, }; Assert.NotStrictEqual(all, returnValue); }