public void ValidateViewModel() { GarmentLeftoverWarehouseReceiptFabricViewModel viewModel = new GarmentLeftoverWarehouseReceiptFabricViewModel() { UnitFrom = null, UENNo = null, ReceiptDate = DateTimeOffset.MinValue, Items = new List <GarmentLeftoverWarehouseReceiptFabricItemViewModel>() { new GarmentLeftoverWarehouseReceiptFabricItemViewModel() } }; var result = viewModel.Validate(null); Assert.True(result.Count() > 0); GarmentLeftoverWarehouseReceiptFabricViewModel viewModel1 = new GarmentLeftoverWarehouseReceiptFabricViewModel() { UnitFrom = null, UENNo = null, ReceiptDate = DateTimeOffset.Now.AddDays(4), Items = new List <GarmentLeftoverWarehouseReceiptFabricItemViewModel>() { new GarmentLeftoverWarehouseReceiptFabricItemViewModel() } }; var result1 = viewModel1.Validate(null); Assert.True(result1.Count() > 0); }
public void validate_Id() { //Setup GarmentLeftoverWarehouseReceiptFabricViewModel viewModel = new GarmentLeftoverWarehouseReceiptFabricViewModel() { UENNo = "1" }; Mock <IServiceProvider> serviceProviderMock = new Mock <IServiceProvider>(); Mock <IGarmentLeftoverWarehouseReceiptFabricService> GarmentLeftoverWarehouseReceiptFabricMock = new Mock <IGarmentLeftoverWarehouseReceiptFabricService>(); GarmentLeftoverWarehouseReceiptFabricMock.Setup(s => s.Read(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <List <string> >(), It.IsAny <string>(), It.IsAny <string>())).Returns(new ReadResponse <GarmentLeftoverWarehouseReceiptFabric>(new List <GarmentLeftoverWarehouseReceiptFabric>(), 1, new Dictionary <string, string>(), new List <string>())); serviceProviderMock.Setup(s => s.GetService(typeof(IGarmentLeftoverWarehouseReceiptFabricService))).Returns(GarmentLeftoverWarehouseReceiptFabricMock.Object); ValidationContext validationContext = new ValidationContext(viewModel, serviceProviderMock.Object, null); //Act var result = viewModel.Validate(validationContext); //Assert Assert.True(0 < result.Count()); }