public async Task Validate_VM_Exist() { var dbContext = DbContext(GetCurrentMethod()); var serviceProvider = GetServiceProviderMock(dbContext).Object; DailyOperationFacade facade = Activator.CreateInstance(typeof(DailyOperationFacade), serviceProvider, dbContext) as DailyOperationFacade; var data = await DataUtil(facade, dbContext).GetTestData(); DailyOperationViewModel vm = new DailyOperationViewModel() { Type = data.Type, Shift = data.Shift, Kanban = new Lib.ViewModels.Kanban.KanbanViewModel() { Id = data.KanbanId }, Step = new Lib.ViewModels.Master.Machine.MachineStepViewModel() { StepId = data.StepId }, Machine = new Lib.ViewModels.Master.Machine.MachineViewModel(), }; System.ComponentModel.DataAnnotations.ValidationContext context = new System.ComponentModel.DataAnnotations.ValidationContext(vm, serviceProvider, null); Assert.NotEmpty(vm.Validate(context)); }
public async Task ValidateVM_Input() { var dbContext = DbContext(GetCurrentMethod()); var serviceProvider = GetServiceProviderMock(dbContext).Object; DailyOperationFacade facade = Activator.CreateInstance(typeof(DailyOperationFacade), serviceProvider, dbContext) as DailyOperationFacade; var data = await DataUtil(facade, dbContext).GetTestData(); DailyOperationViewModel vm = new DailyOperationViewModel() { Type = "input", Shift = "s", Machine = new Lib.ViewModels.Master.Machine.MachineViewModel(), Step = new Lib.ViewModels.Master.Machine.MachineStepViewModel() }; System.ComponentModel.DataAnnotations.ValidationContext context = new System.ComponentModel.DataAnnotations.ValidationContext(vm, serviceProvider, null); Assert.NotEmpty(vm.Validate(context)); vm.TimeInput = 1; Assert.NotEmpty(vm.Validate(context)); vm.Input = 1; Assert.NotEmpty(vm.Validate(context)); vm.DateInput = DateTimeOffset.UtcNow.AddDays(1); Assert.NotEmpty(vm.Validate(context)); vm.DateInput = DateTimeOffset.UtcNow.AddDays(-1); Assert.NotEmpty(vm.Validate(context)); vm.Kanban = new Lib.ViewModels.Kanban.KanbanViewModel() { CurrentStepIndex = data.KanbanStepIndex, Id = data.KanbanId }; Assert.NotEmpty(vm.Validate(context)); vm.Kanban = new Lib.ViewModels.Kanban.KanbanViewModel() { CurrentStepIndex = 2, }; Assert.NotEmpty(vm.Validate(context)); vm.Kanban = new Lib.ViewModels.Kanban.KanbanViewModel() { CurrentStepIndex = 0, Instruction = new Lib.ViewModels.Kanban.KanbanInstructionViewModel() { Steps = new List <Lib.ViewModels.Kanban.KanbanStepViewModel>() { new Lib.ViewModels.Kanban.KanbanStepViewModel() { Process = "a", StepIndex = 1 } } } }; Assert.NotEmpty(vm.Validate(context)); }
public bool ValidateCreateInputDataCheckPreviousOutput(DailyOperationViewModel vm) { if (vm.Kanban.CurrentStepIndex == 0) { return(false); } return(!DbSet.Any(s => s.KanbanId == vm.Kanban.Id && s.Type.ToLower() == "output" && (s.KanbanStepIndex == vm.Kanban.CurrentStepIndex.GetValueOrDefault()))); }
public void Mapping_With_AutoMapper_Profiles() { var configuration = new MapperConfiguration(cfg => { cfg.AddProfile <DailyOperationProfile>(); }); var mapper = configuration.CreateMapper(); DailyOperationViewModel vm = new DailyOperationViewModel { Id = 1 }; DailyOperationModel model = mapper.Map <DailyOperationModel>(vm); Assert.Equal(vm.Id, model.Id); }
public void Validate_VM_NULL() { var dbContext = DbContext(GetCurrentMethod()); var serviceProvider = GetServiceProviderMock(dbContext).Object; DailyOperationViewModel vm = new DailyOperationViewModel() { IsEdit = false, UId = "a", BadOutputDescription = "a" }; var fla = vm.IsChangeable; var desc = vm.BadOutputDescription; System.ComponentModel.DataAnnotations.ValidationContext context = new System.ComponentModel.DataAnnotations.ValidationContext(vm, serviceProvider, null); Assert.NotEmpty(vm.Validate(context)); vm.Type = "s"; var result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.Shift = "s"; result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.Machine = new Lib.ViewModels.Master.Machine.MachineViewModel(); Assert.NotEmpty(vm.Validate(context)); vm.Step = new Lib.ViewModels.Master.Machine.MachineStepViewModel(); result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.Kanban = new Lib.ViewModels.Kanban.KanbanViewModel() { CurrentStepIndex = 0, Instruction = new Lib.ViewModels.Kanban.KanbanInstructionViewModel() { Steps = new List <Lib.ViewModels.Kanban.KanbanStepViewModel>() { new Lib.ViewModels.Kanban.KanbanStepViewModel() { Process = "process" } } } }; result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.Kanban = new Lib.ViewModels.Kanban.KanbanViewModel(); vm.Type = "input"; result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.DateInput = DateTime.Now.AddDays(1); result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.DateInput = null; result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.Input = 0; result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.TimeInput = 0; result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.Type = "output"; vm.BadOutputReasons = new List <DailyOperationBadOutputReasonsViewModel>(); result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.DateOutput = DateTime.Now; vm.BadOutputReasons = new List <DailyOperationBadOutputReasonsViewModel>(); vm.BadOutput = 1; result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.DateOutput = DateTime.Now; vm.BadOutputReasons = new List <DailyOperationBadOutputReasonsViewModel>(); vm.BadOutput = 1; result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.BadOutputReasons = new List <DailyOperationBadOutputReasonsViewModel>() { new DailyOperationBadOutputReasonsViewModel() { Length = 0 } }; vm.BadOutput = 1; result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.DateOutput = DateTime.Now.AddDays(1); result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.DateOutput = null; result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.GoodOutput = -1; result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); vm.TimeOutput = 0; result = vm.Validate(context); Assert.NotEmpty(result); Assert.True(0 < result.Count()); }
public HashSet <int> hasInput(DailyOperationViewModel vm) { return(new HashSet <int>(DbSet.Where(d => d.Kanban.Id == vm.Kanban.Id && d.Type == vm.Type && d.StepId == vm.Step.StepId).Select(d => d.Id))); }
public bool ValidateCreateInputDataCheckDuplicate(DailyOperationViewModel vm) { return(DbSet.Any(s => s.KanbanId == vm.Kanban.Id && s.Type.ToLower() == "input" && s.KanbanStepIndex == (vm.Kanban.CurrentStepIndex.GetValueOrDefault() + 1))); }
//public HashSet<int> hasInput(DailyOperationViewModel vm) //{ // return new HashSet<int>(DbSet.Where(d => d.Kanban.Id == vm.Kanban.Id && d.Type == vm.Type && d.StepId == vm.Step.StepId).Select(d => d.Id)); //} public DailyOperationModel GetInputDataForCurrentOutput(DailyOperationViewModel vm) { return(DbSet.FirstOrDefault(s => s.KanbanId == vm.Kanban.Id && s.Type.ToLower() == "input" && s.KanbanStepIndex == vm.Kanban.CurrentStepIndex.GetValueOrDefault())); }