public async Task GetList_WithoutItemType_PassesExpectedQuery() { GetSuppliersByNameQuery actualQuery = null; var mockMediator = new Mock <IMediator>(); mockMediator .Setup(m => m.Send(It.IsNotNull <IRequest <IEnumerable <ISupplier> > >(), It.IsAny <CancellationToken>())) .Callback <IRequest <IEnumerable <ISupplier> >, CancellationToken>((q, _) => actualQuery = (GetSuppliersByNameQuery)q) .ReturnsAsync(Array.Empty <ISupplier>()); const string expectedName = "Supplier Name"; const PublishedStatus expectedPublishedStatus = PublishedStatus.Draft; var controller = new SuppliersController(mockMediator.Object); var searchQuery = new SupplierSearchQueryModel { Name = expectedName, SolutionPublicationStatus = expectedPublishedStatus, }; await controller.GetList(searchQuery); var expectedQuery = new GetSuppliersByNameQuery(expectedName, expectedPublishedStatus, CatalogueItemType.Solution); actualQuery.Should().BeEquivalentTo(expectedQuery); }
public void GetAllSuppliersReturnsEverythingInRepository() { var allSuppliers = new[] { new Supplier() { Name = "ANTEL", Commission = 1, SupplierId = 1 }, new Supplier() { Name = "OSE", Commission = 2, SupplierId = 2 } }; var mockSupplierService = new Mock <ISupplierService>(); mockSupplierService.Setup(x => x.GetAllSuppliers()).Returns(allSuppliers); var controller = new SuppliersController(mockSupplierService.Object); IHttpActionResult actionResult = controller.GetSuppliers(); OkNegotiatedContentResult <IEnumerable <Supplier> > contentResult = Assert.IsType <OkNegotiatedContentResult <IEnumerable <Supplier> > >(actionResult); Assert.NotNull(contentResult); Assert.NotNull(contentResult.Content); Assert.Same(allSuppliers, contentResult.Content); }
public void Initialize() { //Arrange supplierList = new List <SUPPLIER> { new SUPPLIER { SUPLNO = "1", SUPLNAME = "samsung", SUPLADDR = "South Korea" }, new SUPPLIER { SUPLNO = "2", SUPLNAME = "apple", SUPLADDR = "US" }, new SUPPLIER { SUPLNO = "3", SUPLNAME = "tesla", SUPLADDR = "US" }, new SUPPLIER { SUPLNO = "4", SUPLNAME = "mistibushi", SUPLADDR = "japan" }, new SUPPLIER { SUPLNO = "5", SUPLNAME = "lenova", SUPLADDR = "US" } }.AsQueryable(); mockSupplierSet.As <IQueryable <SUPPLIER> >().Setup(m => m.Provider).Returns(supplierList.Provider); mockSupplierSet.As <IQueryable <SUPPLIER> >().Setup(m => m.Expression).Returns(supplierList.Expression); mockSupplierSet.As <IQueryable <SUPPLIER> >().Setup(m => m.ElementType).Returns(supplierList.ElementType); mockSupplierSet.As <IQueryable <SUPPLIER> >().Setup(m => m.GetEnumerator()).Returns(supplierList.GetEnumerator()); mockSupplierSet.Setup(a => a.Find(It.IsAny <object[]>())).Returns <object[]>(b => supplierList.FirstOrDefault(c => c.SUPLNO == b[0].ToString())); mockContext.Setup(a => a.SUPPLIERs).Returns(mockSupplierSet.Object); mockContext.Setup(a => a.MarkAsModified(It.IsAny <SUPPLIER>())); supplierController = new SuppliersController(mockContext.Object); }
public void DetailsTest() { TestDeploymentContext tdc = new TestDeploymentContext(); //adding one contract, as the contract requires a supplier id ContractDetail x = new ContractDetail() { Contract_ID = 0, Supplier_ID = 0, ContractStartDate = new DateTime(10, 05, 2019), ContractFinishDate = new DateTime(10, 05, 2020), Servicetype = Service.Waste, PriceDescription = "Hourly Price", Price = 22.00, VatRate = 0.135, PriceUpdatedate = new DateTime(01 / 01 / 2019) }; tdc.ContractDetail.Add(x); Assert.IsNotNull(x); tdc.Supplier.Add(new Supplier() { Supplier_ID = 0, SupplierNumber = "SN000", SupplierName = "Tipperary Water", SupplierAddress = "5 Cherry Orchard Industrial Estate, Ballyfermot, Dublin 10.", SupplierCounty = "Dublin", SupplierContact = "Lana kelly", SupplierEMail = "*****@*****.**" }); var controller = new SuppliersController(tdc); var result = controller.Details(0); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(ViewResult)); Supplier y = new Supplier(); //(Supplier)((ViewResult)result).Model; Assert.AreEqual(y.SupplierName, "Tipperary Water"); }
public void GetSpreadsheetDetail_NoState_ReturnsOkResult() { var sut = new SuppliersController(); var result = sut.GetSpreadsheetDetail(); Assert.IsType <OkResult>(result); }
public async void GetSupplier() { // Dodavanje dobavljaca prije dohvacanja using (var context = new StoreSampleContext(_dbContextOptions)) { var suppliersAPI = new SuppliersController(context); for (int i = 0; i < 10; ++i) { Supplier tmpSupplier = new Supplier(); tmpSupplier.CompanyName = $"Kompanija { i + 1 }"; tmpSupplier.City = "Zagreb"; tmpSupplier.Country = "Hrvatska"; tmpSupplier.Phone = $"01 234 567{ i }"; suppliersAPI.PostSupplier(tmpSupplier).Wait(); } } using (var context = new StoreSampleContext(_dbContextOptions)) { var suppliersAPI = new SuppliersController(context); var result = await suppliersAPI.GetSupplier(5); var okResult = result as OkObjectResult; // Ako je rezultat Ok i status kod je 200, tada je poziv uspjesan Assert.NotNull(okResult); Assert.Equal(200, okResult.StatusCode); // Ako je dohvacen dobavljac sa ispravnim brojem telefona, poziv je uspjesan Supplier supplier = okResult.Value as Supplier; Assert.NotNull(supplier); Assert.Equal("01 234 5674", supplier.Phone); } }
public void Suppliers_Create() { // Arrange db = new AlexaDbContextTest(); supplierService = new SupplierService(new SupplierRepositoryTest(db), new GroupRepositoryTest(db)); groupService = new GroupService(new SupplierRepositoryTest(db), new GroupRepositoryTest(db)); controller = new SuppliersController(supplierService, groupService); var supplier = new SupplierDto { ID = 5, Name = "test", Address = "test", Email = "test", Phone = "123 456 789", Groups = new List <GroupDto>() { groupService.GetById(0) } }; // Act ViewResult result_1 = controller.Create(supplier) as ViewResult; ViewResult result_2 = controller.Details(5) as ViewResult; // Assert Assert.IsNotNull(result_2); Assert.IsInstanceOfType(result_2.ViewData.Model, typeof(SupplierDto)); var supplier_edit = (SupplierDto)result_2.ViewData.Model; Assert.AreEqual(supplier_edit.Name, "test"); }
static void Main(string[] args) { SuppliersController callSupplier = new SuppliersController(); ItemsController callItem = new ItemsController(); TransactionsController callTransaction = new TransactionsController(); Console.WriteLine("=========== Manage Data ============"); Console.WriteLine("1. Item"); Console.WriteLine("2. Supplier"); Console.WriteLine("3. Transaction"); Console.WriteLine("===================================="); Console.Write("Going to : "); int chance = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("===================================="); if (chance == 1) { callItem.ManageItem(); } else if (chance == 2) { callSupplier.ManageSupplier(); } else if (chance == 3) { //callTransaction.ManageTransaction(); callTransaction.Print(); } else { Console.WriteLine("Something is wrong, please try again."); Console.Read(); } }
private void AddFieldsBy(TradePointRequest request) { List <TradePoint> tradePoints = TradePointsController.GetInstance().GetTradePoints(); TradePoint currTradePoint; try { currTradePoint = request.TradePoint == null?tradePoints.First() : tradePoints.Find(x => x.Id == request.TradePoint.Id); } catch (Exception ex) { currTradePoint = null; } ComboBox tradePointCB = GetComboBoxOnData(tradePoints.ToList <object>(), currTradePoint, "FullName"); List <Product> products = ProductsController.GetInstance().GetProducts(); Product currProduct; try { currProduct = request.Product == null || request.Product.Product == null?products.First() : products.Find(x => x.Id == request.Product.Product.Id); } catch (Exception ex) { currProduct = null; } ComboBox productCB = GetComboBoxOnData(products.ToList <object>(), currProduct, "Name"); List <Supplier> suppliers = SuppliersController.GetInstance().GetSuppliers(); Supplier currSupplier; try { currSupplier = request.Product == null || request.Product.Supplier == null?suppliers.First() : suppliers.Find(x => x.Id == request.Product.Supplier.Id); } catch (Exception ex) { currSupplier = null; } ComboBox supplierCB = GetComboBoxOnData(suppliers.ToList <object>(), currSupplier, "Name"); int count = request.Product == null ? 0 : request.Product.Count; TextBox countTB = new TextBox() { Text = count.ToString(), Margin = new Thickness(5, 5, 5, 5), Width = 200 }; countTB.PreviewTextInput += NumberValidationTextBox; Elements.Children.Add(supplierCB); Elements.Children.Add(productCB); Elements.Children.Add(countTB); Elements.Children.Add(tradePointCB); comboBoxes.Add(supplierCB); comboBoxes.Add(productCB); comboBoxes.Add(tradePointCB); textBoxes.Add(countTB); }
public void SetUp() { controller = new SuppliersController(); controller.DbSession = session; supplier = DataMother.CreateSupplier(); session.Save(supplier); Prepare(controller); }
public void TestSupllierIndex() { var obj = new SuppliersController(); var actResult = obj.Index() as ViewResult; Assert.That(actResult.ViewName, Is.EqualTo("Index")); }
public void Create() { ApplicationDbContext context = new ApplicationDbContext(); IUnitOfWork unitOfWork = new UnitOfWork(context); var controller = new SuppliersController(unitOfWork); var result = controller.Create() as ViewResult; Assert.AreEqual(expected: "Create", actual: result.ViewName); }
public void UpdateList() { List <Supplier> suppliersList = SuppliersController.GetInstance().GetSuppliers(); suppliersList.Sort((x, y) => x.Name.CompareTo(y.Name)); suppliers = new ObservableCollection <Supplier>(suppliersList); SuppliersList.ItemsSource = suppliers; SuppliersList.Items.Refresh(); SuppliersList.UpdateLayout(); }
public SuppliesUC() { InitializeComponent(); List <TradePoint> tradePointsList = TradePointsController.GetInstance().GetTradePoints(); tradePointsList.Sort((x, y) => x.FullName.CompareTo(y.FullName)); TradePoints = new ObservableCollection <TradePoint>(tradePointsList); Binding bind1 = new Binding(); bind1.Source = TradePoints; TradePointComboBox.DisplayMemberPath = "FullName"; TradePointComboBox.SetBinding(ComboBox.ItemsSourceProperty, bind1); TradePoint = TradePoints.FirstOrDefault(); TradePointComboBox.SelectedItem = TradePoint; List <Product> productsList = ProductsController.GetInstance().GetProducts(); Products = new ObservableCollection <Product>(productsList); Binding bind2 = new Binding(); bind2.Source = Products; ProductComboBox.DisplayMemberPath = "Name"; ProductComboBox.SetBinding(ComboBox.ItemsSourceProperty, bind2); Product = Products.FirstOrDefault(); ProductComboBox.SelectedItem = Product; List <Supplier> suppliersList = SuppliersController.GetInstance().GetSuppliers(); Suppliers = new ObservableCollection <Supplier>(suppliersList); Binding bind3 = new Binding(); bind3.Source = Suppliers; SupplierComboBox.DisplayMemberPath = "Name"; SupplierComboBox.SetBinding(ComboBox.ItemsSourceProperty, bind3); Supplier = Suppliers.FirstOrDefault(); SupplierComboBox.SelectedItem = Supplier; List <Order> ordersList = OrdersController.GetInstance().GetOrders(); Orders = new ObservableCollection <Order>(ordersList); Binding bind4 = new Binding(); bind4.Source = Orders; OrderComboBox.DisplayMemberPath = "Id"; OrderComboBox.SetBinding(ComboBox.ItemsSourceProperty, bind4); Order = Orders.FirstOrDefault(); OrderComboBox.SelectedItem = Order; }
public void SetUp() { _supplierService = Substitute.For <ISupplierService>(); _suppliersController = new SuppliersController(_supplierService); Mapper.Initialize(c => c.AddProfile <MappingProfile>()); _contextBase = Substitute.For <HttpContextBase>(); _contextBase.User.Identity.Name.Returns("JohnDoe"); _contextBase.Request.IsAuthenticated.Returns(true); _contextBase.User.IsInRole("Admin").Returns(true); _suppliersController.ControllerContext = new ControllerContext(_contextBase, new RouteData(), _suppliersController); }
private void ApplyChangesBy(Supplier supplier) { supplier.Name = textBoxes[0].Text; if (supplier.Id < 0) { SuppliersController.GetInstance().AddSupplier(supplier); } else { SuppliersController.GetInstance().EditSupplier(supplier); } }
public async Task Can_get_all_Suppliers_in_database() { using (var context = new ProcurementDbContext(ContextOptions)) { SuppliersController suppliersController = new SuppliersController(context); var result = await suppliersController.GetSuppliers(); var viewResult = Assert.IsType <ActionResult <IEnumerable <Supplier> > >(result); var suppliers = Assert.IsType <List <Supplier> >(viewResult.Value); Assert.Equal(3, suppliers.Count); } }
public async void Task1_GetById_Return_OkResult() { //Arrange var Id = 1; _context = new SDCContext(dbContextOptions); _controller = new SuppliersController(_context); //Act var result = await _controller.GetSupplier(Id); //Assert Assert.IsType <OkObjectResult>(result); }
public async Task DeleteConfirmed_Redirects() { // Arrange var mockRepo = new Mock <IInvoicesRepository>(); var controller = new SuppliersController(mockRepo.Object); // Act var result = await controller.DeleteConfirmed(1); // Assert var redirect = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", redirect.ActionName); }
public void Create_ReturnsViewResultWithoutModel() { // Arrange var mockRepo = new Mock <IInvoicesRepository>(); var controller = new SuppliersController(mockRepo.Object); // Act var result = controller.Create(); // Assert var viewResult = Assert.IsType <ViewResult>(result); Assert.Null(viewResult.ViewData.Model); }
private void AddFieldsBy(Order order) { DatePicker datePicker = new DatePicker() { SelectedDate = order.Date, IsDropDownOpen = false, Margin = new Thickness(5, 5, 5, 5), Width = 200 }; List <Product> products = ProductsController.GetInstance().GetProducts(); Product currProduct; try { currProduct = order.Product.Product == null?products.First() : products.Find(x => x.Id == order.Product.Product.Id); } catch (Exception ex) { currProduct = null; } ComboBox productCB = GetComboBoxOnData(products.ToList <object>(), currProduct, "Name"); List <Supplier> suppliers = SuppliersController.GetInstance().GetSuppliers(); Supplier currSupplier; try { currSupplier = order.Product.Supplier == null?suppliers.First() : suppliers.Find(x => x.Id == order.Product.Supplier.Id); } catch (Exception ex) { currSupplier = null; } ComboBox supplierCB = GetComboBoxOnData(suppliers.ToList <object>(), currSupplier, "Name"); TextBox countTB = new TextBox() { Text = order.Product.Count.ToString(), Margin = new Thickness(5, 5, 5, 5), Width = 200 }; countTB.PreviewTextInput += NumberValidationTextBox; Elements.Children.Add(datePicker); Elements.Children.Add(productCB); Elements.Children.Add(supplierCB); Elements.Children.Add(countTB); datePickers.Add(datePicker); comboBoxes.Add(productCB); comboBoxes.Add(supplierCB); textBoxes.Add(countTB); }
public async void Task2_GetById_Return_NotFoundResult() { //Arrange var Id = 82; _context = new SDCContext(dbContextOptions); _controller = new SuppliersController(_context); //Act var result = await _controller.GetSupplier(Id); //Assert Assert.IsType <NotFoundResult>(result); }
public void Suppliers_Index() { // Arrange db = new AlexaDbContextTest(); supplierService = new SupplierService(new SupplierRepositoryTest(db), new GroupRepositoryTest(db)); groupService = new GroupService(new SupplierRepositoryTest(db), new GroupRepositoryTest(db)); controller = new SuppliersController(supplierService, groupService); // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); }
public SupplierControllerTests() { var mapperConfig = new MapperConfiguration(config => { config.AddProfiles(new Profile[] { new SupplierProfile(), new LocationProfile(), new ProductProfile() }); }); var mapper = mapperConfig.CreateMapper(); _supplierService = new Mock <ISupplierService>(); _suppliersController = new SuppliersController(_supplierService.Object, mapper); }
public async Task Get_SupplierNotFound_ReturnsNotFound() { const string id = "1"; var mockMediator = new Mock <IMediator>(); mockMediator.Setup(m => m.Send(It.IsNotNull <IRequest <ISupplier> >(), It.IsAny <CancellationToken>())) .ReturnsAsync((ISupplier)null); var controller = new SuppliersController(mockMediator.Object); var response = await controller.Get(id); response.Should().BeEquivalentTo(new ActionResult <GetSupplierModel>(new NotFoundResult())); }
public async Task Can_delete_Supplier_by_SupplierCode() { const string SUPPLIERCODE = "SP1"; using (var context = new ProcurementDbContext(ContextOptions)) { SuppliersController suppliersController = new SuppliersController(context); var result = await suppliersController.DeleteSupplier(SUPPLIERCODE); var viewResult = Assert.IsType <ActionResult <Supplier> >(result); var model = Assert.IsType <Supplier>(viewResult.Value); Assert.Equal(SUPPLIERCODE, model.SupplierCode); } }
public async Task Can_get_Supplier_details_by_SupplierCode() { const string SUPPLIERCODE = "SP1"; using (var context = new ProcurementDbContext(ContextOptions)) { SuppliersController suppliersController = new SuppliersController(context); var result = await suppliersController.GetSupplier(SUPPLIERCODE); var viewResult = Assert.IsType <ActionResult <Supplier> >(result); var supplier = Assert.IsType <Supplier>(viewResult.Value); Assert.NotNull(supplier); Assert.Equal(SUPPLIERCODE, supplier.SupplierCode); } }
public async Task Should_not_return_Supplier_when_SupplierCode_not_existing() { const string SUPPLIERCODE = "SP001"; using (var context = new ProcurementDbContext(ContextOptions)) { SuppliersController suppliersController = new SuppliersController(context); var result = await suppliersController.GetSupplier(SUPPLIERCODE); var viewResult = Assert.IsType <ActionResult <Supplier> >(result); Assert.IsNotType <Supplier>(viewResult.Value); var response = Assert.IsType <NotFoundResult>(viewResult.Result); Assert.Equal(404, response.StatusCode); } }
public async Task GetList_NoSuppliersFound_ReturnsExpectedResponse() { var expectedSuppliers = Array.Empty <GetSupplierModel>(); var mockMediator = new Mock <IMediator>(); mockMediator .Setup(m => m.Send(It.IsNotNull <IRequest <IEnumerable <ISupplier> > >(), It.IsAny <CancellationToken>())) .ReturnsAsync(Array.Empty <ISupplier>()); var controller = new SuppliersController(mockMediator.Object); var response = await controller.GetList(new SupplierSearchQueryModel()); response.Should().BeEquivalentTo( new ActionResult <IEnumerable <GetSupplierModel> >(new OkObjectResult(expectedSuppliers))); }
public async void Task4_Put_Update_Supplier_NoContentResult() { //Arrange _context = new SDCContext(dbContextOptions); _controller = new SuppliersController(_context); int newId = 59; //Act var supplier = new Supplier() { SupplierId = newId, Company = "Update Zuo" }; var updatedData = await _controller.PutSupplier(newId, supplier); //Assert Assert.IsType <NoContentResult>(updatedData); }