public async Task UpdateAdviceScope() { var adviceScope = new AdviceScope() { Id = Guid.NewGuid(), Name = "Name1" }; var service = new Mock <IDirectoryLookupService>(); var result = new Result() { Success = true }; AdviceScope updated = null; service.Setup(c => c.UpdateAdviceScope(It.IsAny <AdviceScope>())) .Callback((AdviceScope i) => { updated = i; }) .ReturnsAsync(result); var controller = new LookupsController(service.Object); var actual = await controller.UpdateAdviceScope(adviceScope.Id.Value, adviceScope); Assert.Same(adviceScope, updated); var okResult = Assert.IsType <OkObjectResult>(actual); var returnValue = Assert.IsType <Result>(okResult.Value); Assert.Same(result, returnValue); }
public async Task InsertAdviceScope() { var options = TestHelper.GetDbContext("InsertAdviceScope"); //Given var model = new AdviceScope() { Name = "1", }; using (var context = new DataContext(options)) { var service = new DirectoryLookupService(context); //When var result = await service.InsertAdviceScope(model); //Then Assert.True(result.Success); var actual = await context.AdviceScope.FindAsync(((AdviceScope)result.Tag).Id); Assert.Equal(model.Name, actual.Name); } }
public async Task AdviceScopes() { var adviceScope = new AdviceScope() { Id = Guid.NewGuid(), Name = "Name1" }; var adviceScopes = new List <AdviceScope>() { adviceScope }; var service = new Mock <IDirectoryLookupService>(); service.Setup(c => c.GetAdviceScopes()) .ReturnsAsync(adviceScopes); var controller = new LookupsController(service.Object); var result = await controller.AdviceScopes(); var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <List <AdviceScope> >(okResult.Value); Assert.Same(adviceScopes, returnValue); }
private AdviceScopeEntity MapAdviceScopeModelToEntity(AdviceScope model, AdviceScopeEntity entity = null) { if (entity == null) { entity = new AdviceScopeEntity(); } entity.Name = model.Name; return(entity); }
public async Task <IActionResult> InsertAdviceScope([FromBody] AdviceScope model) { var result = await LookupService.InsertAdviceScope(model); if (!result.Success) { return(BadRequest(result.ValidationFailures)); } return(Ok(result)); }
public async Task <IActionResult> UpdateAdviceScope(Guid adviceScopeId, [FromBody] AdviceScope model) { model.Id = adviceScopeId; var result = await LookupService.UpdateAdviceScope(model); if (!result.Success) { return(BadRequest(result.ValidationFailures)); } return(Ok(result)); }
public static IAdviceBuilder GetAdviceBuilder( IAspectConstruction construction = null, MethodInfo method = null, AdviceExecution execution = AdviceExecution.Before, AdviceScope scope = AdviceScope.Instance) { construction = construction ?? GetConstruction(); method = method ?? GetMethodInfo(); return(new AdviceBuilder() .SetConstruction(construction) .SetMethod(method) .SetExecution(execution) .SetScope(scope)); }
private void CheckThrowForMissing( string missingMember, IAspectConstruction construction = null, MethodInfo method = null, AdviceExecution execution = AdviceExecution.Undefined, AdviceScope scope = AdviceScope.Undefined) { var builder = new AdviceBuilder() .SetConstruction(construction) .SetMethod(method) .SetExecution(execution) .SetScope(scope); var message = string.Format("Cannot build advice without having set its {0}.", missingMember); Assert.That(() => builder.Build(), Throws.InvalidOperationException.With.Message.EqualTo(message)); }
public static Advice GetAdvice( IAspectConstruction construction = null, MethodInfo method = null, string role = null, string name = null, AdviceExecution execution = AdviceExecution.Around, AdviceScope scope = AdviceScope.Static, int priority = 0, IEnumerable <IPointcut> pointcuts = null) { construction = construction ?? GetConstruction(); method = method ?? GetMethodInfo(); name = name ?? "name"; role = role ?? "role"; pointcuts = pointcuts ?? new IPointcut[0]; return(new Advice(construction, method, name, role, execution, scope, priority, pointcuts)); }
public async Task <Result> InsertAdviceScope(AdviceScope model) { var validator = new AdviceScopeValidator(true); var result = validator.Validate(model).GetResult(); if (!result.Success) { return(result); } var entity = MapAdviceScopeModelToEntity(model); await _context.AdviceScope.AddAsync(entity); await _context.SaveChangesAsync(); model.Id = entity.Id; result.Tag = model; return(result); }
public async Task <Result> UpdateAdviceScope(AdviceScope model) { var validator = new AdviceScopeValidator(false); var result = validator.Validate(model).GetResult(); if (!result.Success) { return(result); } var entity = await _context.AdviceScope.FindAsync(model.Id); if (entity == null) { return(new Result()); } entity = MapAdviceScopeModelToEntity(model, entity); await _context.SaveChangesAsync(); return(result); }
public async Task UpdateAdviceScope() { var options = TestHelper.GetDbContext("UpdateAdviceScope"); //Given var lkp1 = new AdviceScopeEntity { Id = Guid.NewGuid(), Name = "1" }; using (var context = new DataContext(options)) { context.AdviceScope.Add(lkp1); context.SaveChanges(); } var model = new AdviceScope() { Id = lkp1.Id, Name = "1 Updated", }; using (var context = new DataContext(options)) { var service = new DirectoryLookupService(context); //When var result = await service.UpdateAdviceScope(model); //Then Assert.True(result.Success); var actual = await context.AdviceScope.FindAsync(model.Id); Assert.Equal(model.Name, actual.Name); } }
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); }