コード例 #1
0
        public void Sell_ModelStateError_Test()
        {
            //Arrange
            Mock <ICategoriesRepository> category = new Mock <ICategoriesRepository>();

            category.Setup(m => m.Categories).Returns(new[]
            {
                new Category
                {
                    CategoryId   = 1,
                    CategoryName = "Cat1",
                },
                new Category
                {
                    CategoryId   = 1,
                    CategoryName = "Cat2",
                },
                new Category
                {
                    CategoryId   = 1,
                    CategoryName = "Cat3",
                }
            }.AsQueryable());
            SellerController controller = new SellerController(null, category.Object);

            controller.ModelState.AddModelError("test", "test");
            SellModel q = new SellModel {
                Name = "P1", Files = new List <HttpPostedFileBase>()
            };
            //Act
            ActionResult result = controller.Sell(q, "Cat3");

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
コード例 #2
0
        public void Return_SameView_When_ModelState_is_Invalid()
        {
            // Arrange
            var domainService    = new Mock <IDomainService>();
            var userService      = new Mock <IUserService>();
            var loggedInUser     = new Mock <ILoggedInUser>();
            var sellerController = new SellerController(userService.Object, domainService.Object, loggedInUser.Object);

            sellerController.ModelState.AddModelError("", "dummy error");

            var userId = "userId";

            loggedInUser.Setup(l => l.GetUserId()).Returns(userId);

            AddDomainViewModel addDomainViewModel = new AddDomainViewModel()
            {
                Name        = "name",
                Description = "description"
            };

            // Act & Assert
            sellerController
            .WithCallTo(s => s.AddDomain(addDomainViewModel))
            .ShouldRenderDefaultView()
            .WithModel <AddDomainViewModel>();
        }
コード例 #3
0
        private void ToolStripDeleteButton_Click(object sender, EventArgs e)
        {
            SaleController saleController = new SaleController();

            if (!saleController.IsOpen)
            {
                DialogResult dr = MessageBox.Show("Are you sure you wish to delete this user?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dr == DialogResult.Yes)
                {
                    if (SellerGrid.SelectedRows != null && SellerGrid.SelectedRows.Count > 0)
                    {
                        int id;
                        int.TryParse(SellerGrid.SelectedRows[0].Cells[2].Value.ToString(), out id);

                        if (id > 0)
                        {
                            SellerController sellerController = new SellerController();
                            sellerController.Remove(id);
                            LoadSellers();
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Cannot delete a seller while a sale is open. Please complete the sale and try again.", "Delete Seller", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #4
0
        public void Call_DomainService_AddDomain_Once()
        {
            // Arrange
            var domainService    = new Mock <IDomainService>();
            var userService      = new Mock <IUserService>();
            var loggedInUser     = new Mock <ILoggedInUser>();
            var sellerController = new SellerController(userService.Object, domainService.Object, loggedInUser.Object);

            var userId = "userId";

            loggedInUser.Setup(l => l.GetUserId()).Returns(userId);

            AddDomainViewModel addDomainViewModel = new AddDomainViewModel()
            {
                Name        = "name",
                Description = "description"
            };

            // Act
            sellerController.AddDomain(addDomainViewModel);

            // Assert
            domainService.Verify(
                d => d.AddDomain(addDomainViewModel.Name, addDomainViewModel.Description, userId), Times.Once());
        }
コード例 #5
0
        public void Sell_Test()
        {
            // Arrange
            Mock <ICategoriesRepository> category = new Mock <ICategoriesRepository>();

            category.Setup(m => m.Categories).Returns(new[]
            {
                new Category
                {
                    CategoryId   = 1,
                    CategoryName = "Cat1",
                },
                new Category
                {
                    CategoryId   = 1,
                    CategoryName = "Cat2",
                },
                new Category
                {
                    CategoryId   = 1,
                    CategoryName = "Cat3",
                }
            }.AsQueryable());
            SellerController target = new SellerController(null, category.Object);

            target.Sell();
        }
コード例 #6
0
        private void EditStartingCash_Load(object sender, EventArgs e)
        {
            SellerController sellerController = new SellerController();

            cboContBy.DisplayMember = "name";
            cboContBy.ValueMember   = "id";
            cboContBy.DataSource    = sellerController.GetAll();
        }
コード例 #7
0
        private void PopulateSellerDropdown()
        {
            SellerController sellerController = new SellerController();

            cboSeller.DisplayMember = "name";
            cboSeller.ValueMember   = "id";
            cboSeller.DataSource    = sellerController.GetAll();
        }
コード例 #8
0
        public void Sell_ModelStateValid_Test()
        {
            // Arrange
            Mock <ICategoriesRepository> category = new Mock <ICategoriesRepository>();

            category.Setup(m => m.Categories).Returns(new[]
            {
                new Category
                {
                    CategoryId   = 1,
                    CategoryName = "Cat1",
                },
                new Category
                {
                    CategoryId   = 1,
                    CategoryName = "Cat2",
                },
                new Category
                {
                    CategoryId   = 1,
                    CategoryName = "Cat3",
                }
            }.AsQueryable());
            Mock <ILotsRepository> mock = new Mock <ILotsRepository>();

            mock.Setup(m => m.Lots).Returns(new[]
            {
                new Lot {
                    LotID = 1, Name = "P1", IsCompleted = false
                },
                new Lot {
                    LotID = 2, Name = "P2", IsCompleted = false
                },
                new Lot {
                    LotID = 3, Name = "P3", IsCompleted = false
                },
                new Lot {
                    LotID = 4, Name = "P4", IsCompleted = false
                },
            }.AsQueryable());
            SellerController controller = new SellerController(mock.Object, category.Object);

            controller.ModelState.Clear();
            SellModel q = new SellModel {
                Name = "P1", Files = new List <HttpPostedFileBase>(), Description = "1"
            };
            //Act
            ActionResult result = controller.Sell(q, "Cat3");

            // Assert
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            RedirectToRouteResult routeResult = result as RedirectToRouteResult;

            Assert.AreEqual(routeResult.RouteValues["action"], "Lot");
        }
コード例 #9
0
        public void Create_Instance_Of_Controller_WhenArgumentsAreCorrect()
        {
            // Arrange
            var domainService = new Mock <IDomainService>();
            var userService   = new Mock <IUserService>();
            var loggedInUser  = new Mock <ILoggedInUser>();

            // Act
            var sellerController = new SellerController(userService.Object, domainService.Object, loggedInUser.Object);

            // Assert
            Assert.IsInstanceOf <Controller>(sellerController);
        }
コード例 #10
0
        public async Task GetListAdminsTestAsync()
        {
            // Arrange
            mockSellerService.Setup(service => service.ListSellersAsync()).ReturnsAsync(await userHelper.GetUsers());
            SellerController controller = new SellerController(mockSellerService.Object);

            // Act
            var result = await controller.ListSellers();

            var okResult = Assert.IsType <OkObjectResult>(result);
            var model    = Assert.IsType <List <UserViewDto> >(okResult.Value);

            // Assert
            Assert.Equal((await userHelper.GetUsers()).FirstOrDefault(f => f.Email == userHelper.EmailUser).Email, model.FirstOrDefault(f => f.Email == userHelper.EmailUser).Email);
        }
コード例 #11
0
        private void HandleBlockSpawned(BlockView blockView, BlockData data)
        {
            var sellerView = blockView.GetComponentInChildren <SellerView>();

            if (sellerView != null)
            {
                var sellerController = new SellerController(sellerView.SellerControllerConfig)
                {
                    Position = sellerView.transform.position
                };

                stores[sellerView] = sellerController;

                sellerController.OnStoreOpened += sellerView.OpenTheDoor;
                sellerController.OnStoreOpened += HandleStoreOpened;
            }
        }
コード例 #12
0
        private void LoadSellers()
        {
            int currentRow = 0;

            if (SellerGrid.CurrentRow != null)
            {
                currentRow = SellerGrid.CurrentRow.Index;
            }

            SellerController sellerController = new SellerController();

            SellerGrid.DataSource = sellerController.GetAll();
            SetUpGrid();

            if (SellerGrid.Rows.Count > 0)
            {
                if (SellerGrid.Rows.Count > currentRow)
                {
                    SellerGrid.CurrentCell = SellerGrid.Rows[currentRow].Cells[3];
                }
                else
                {
                    SellerGrid.CurrentCell = SellerGrid.Rows[0].Cells[3];
                }

                ToolStripEditButton.Enabled       = true;
                ToolStripDeleteButton.Enabled     = true;
                EditUserToolStripMenuItem.Enabled = true;
                DeleteToolStripMenuItem.Enabled   = true;
            }
            else
            {
                ToolStripEditButton.Enabled       = false;
                ToolStripDeleteButton.Enabled     = false;
                EditUserToolStripMenuItem.Enabled = false;
                DeleteToolStripMenuItem.Enabled   = false;
            }
        }
コード例 #13
0
ファイル: Edit_Should.cs プロジェクト: martinst1/Brandviser
        public void RenderDefaultView_WithExpectedViewModel()
        {
            // Arrange
            var domainService    = new Mock <IDomainService>();
            var userService      = new Mock <IUserService>();
            var loggedInUser     = new Mock <ILoggedInUser>();
            var sellerController = new SellerController(userService.Object, domainService.Object, loggedInUser.Object);

            string name = "name";

            Guid guid = Guid.NewGuid();

            var domain = new Domain()
            {
                Id          = 1,
                Name        = "name",
                Description = "description",
                Price       = 1,
                OriginalOwnerCustomPrice = 1
            };

            domainService.Setup(d => d.GetDomainByName(name + ".com")).Returns(domain);

            // Act & Assert
            sellerController
            .WithCallTo(s => s.Edit(name))
            .ShouldRenderDefaultPartialView()
            .WithModel <EditDomainViewModel>(
                e =>
            {
                Assert.AreEqual(1, e.Id);
                Assert.AreEqual("name", e.Name);
                Assert.AreEqual("description", e.Description);
                Assert.AreEqual(1, e.Price);
                Assert.AreEqual(1, e.OwnerCustomPrice);
            });
        }
コード例 #14
0
        public void Set_TempData_SuccessMessage()
        {
            // Arrange
            var domainService    = new Mock <IDomainService>();
            var userService      = new Mock <IUserService>();
            var loggedInUser     = new Mock <ILoggedInUser>();
            var sellerController = new SellerController(userService.Object, domainService.Object, loggedInUser.Object);

            var userId = "userId";

            loggedInUser.Setup(l => l.GetUserId()).Returns(userId);

            AddDomainViewModel addDomainViewModel = new AddDomainViewModel()
            {
                Name        = "name",
                Description = "description"
            };

            // Act
            sellerController.AddDomain(addDomainViewModel);

            // Assert
            sellerController.ShouldHaveTempDataProperty("Success", "Added successfully!");
        }
コード例 #15
0
        public void Call_GetUserByStringId_From_UserService_Once()
        {
            // Arrange
            var domainService    = new Mock <IDomainService>();
            var userService      = new Mock <IUserService>();
            var loggedInUser     = new Mock <ILoggedInUser>();
            var sellerController = new SellerController(userService.Object, domainService.Object, loggedInUser.Object);

            string userId    = "userId";
            var    createdOn = new DateTime(17, 1, 1);
            var    user      = new User()
            {
                Id = userId, FirstName = "firstname", LastName = "lastname"
            };

            var rejectedDomains = new List <Domain>()
            {
                new Domain()
                {
                    StatusId = 2
                }
            };
            var pendingDomains = new List <Domain>()
            {
                new Domain()
                {
                    StatusId = 1
                }
            };
            var publishedDomains = new List <Domain>()
            {
                new Domain()
                {
                    StatusId = 4
                }
            };
            var soldDomains = new List <Domain>()
            {
                new Domain()
                {
                    StatusId = 5
                }
            };

            user.SellerDomains.Add(rejectedDomains[0]);
            user.SellerDomains.Add(pendingDomains[0]);
            user.SellerDomains.Add(publishedDomains[0]);
            user.SellerDomains.Add(soldDomains[0]);
            user.CreatedOn = createdOn;
            user.Balance   = 10000;

            loggedInUser.Setup(l => l.GetUserId()).Returns(userId);

            userService.Setup(u => u.GetUserByStringId(userId)).Returns(user);

            // Act
            sellerController.Index();

            // Assert
            userService.Verify(u => u.GetUserByStringId(userId), Times.Once());
        }
コード例 #16
0
 public void SetUp()
 {
     mockSellerManager = new Mock <ISellerManager>();
     sellerController  = new SellerController(mockSellerManager.Object);
 }
コード例 #17
0
        public void RenderDefaultView_WithExpectedViewModel()
        {
            // Arrange
            var domainService    = new Mock <IDomainService>();
            var userService      = new Mock <IUserService>();
            var loggedInUser     = new Mock <ILoggedInUser>();
            var sellerController = new SellerController(userService.Object, domainService.Object, loggedInUser.Object);

            string userId    = "userId";
            var    createdOn = new DateTime(17, 1, 1);
            var    user      = new User()
            {
                Id = userId, FirstName = "firstname", LastName = "lastname"
            };

            var rejectedDomains = new List <Domain>()
            {
                new Domain()
                {
                    StatusId = 2
                }
            };
            var pendingDomains = new List <Domain>()
            {
                new Domain()
                {
                    StatusId = 1
                }
            };
            var publishedDomains = new List <Domain>()
            {
                new Domain()
                {
                    StatusId = 4
                }
            };
            var soldDomains = new List <Domain>()
            {
                new Domain()
                {
                    StatusId = 5
                }
            };

            user.SellerDomains.Add(rejectedDomains[0]);
            user.SellerDomains.Add(pendingDomains[0]);
            user.SellerDomains.Add(publishedDomains[0]);
            user.SellerDomains.Add(soldDomains[0]);
            user.CreatedOn = createdOn;
            user.Balance   = 10000;

            loggedInUser.Setup(l => l.GetUserId()).Returns(userId);

            userService.Setup(u => u.GetUserByStringId(userId)).Returns(user);

            // Act & Assert
            sellerController
            .WithCallTo(s => s.Index())
            .ShouldRenderDefaultView()
            .WithModel <SellerProfileBoxStatsViewModel>(
                s =>
            {
                Assert.AreEqual(user.FirstName + " " + user.LastName, s.FullName);
                Assert.AreEqual(user.FirstName[0].ToString() + user.LastName[0].ToString(), s.Initials);
                Assert.AreEqual(createdOn, s.MemberSince);
                Assert.AreEqual(Math.Round(user.Balance / 1000, 0) + "k", s.BalanceInKUsd);
                Assert.AreEqual(10000, s.Balance);
                Assert.AreEqual(4, s.SubmittedDomains);
                Assert.AreEqual(1, s.RejectedDomains);
                Assert.AreEqual(1, s.PendingDomains);
                Assert.AreEqual(1, s.PublishedDomains);
                Assert.AreEqual(1, s.SoldDomains);
            });
        }