private readonly Mock <ILogger <ShopsController> > logger;    //create Moq object of Serilog

        public ShopsControllerTests()
        {
            mockService = new Mock <IService>();

            logger = new Mock <ILogger <ShopsController> >();

            //Setup moq controller with moq objects and local version of automapper
            shopsController        = new ShopsController(mockService.Object, logger.Object);
            expectedShopViewModels = GetExpectedShopViewModels();

            //Setup all methods of the moq object of Repository
            mockService.Setup(m => m.GetListShops()).Returns(Task.FromResult(expectedShopViewModels));

            mockService.Setup(m => m.AddShop(It.IsAny <AddShopViewModel>()))
            .Returns((AddShopViewModel target) =>
            {
                ShopViewModel model = new ShopViewModel()
                {
                    Id        = 2,
                    ShopName  = target.ShopName,
                    Address   = target.Address,
                    FullNames = null,
                    Dates     = null
                };

                expectedShopViewModels.Add(model);
                return(Task.FromResult(true));
            });
        }
Ejemplo n.º 2
0
        public void isShopValidReturnsTrue()
        {
            var dbMock     = new Mock <IShopRepository>();
            var dbConf     = new Mock <IConfiguration>();
            var controller = new ShopsController(dbMock.Object, dbConf.Object);
            var shop       = new Shop()
            {
                Id          = 1,
                Address     = "a",
                Name        = "a",
                PhoneNumber = "a",
                Password    = "******"
            };

            var result = controller.isShopValid(shop);

            Assert.True(result);
        }
Ejemplo n.º 3
0
        public void PostDeleteShopReturns403()
        {
            var dbMock         = new Mock <IShopRepository>();
            var dbConf         = new Mock <IConfiguration>();
            var controllerMock = new Mock <ShopsController>(dbMock.Object, dbConf.Object);

            controllerMock.Setup(f => f.isSuperAdmin(" ")).Returns(false);
            ShopsController controller = controllerMock.Object;

            var resultPost = controller.PostShop(new SuperAdminRequest()
            {
                RootPassword = "******"
            });
            var resultDelete = controller.DeleteShop(new SuperAdminRequest()
            {
                RootPassword = "******"
            });

            Assert.Equal(403, resultPost.StatusCode);
            Assert.Equal(403, resultDelete.StatusCode);
        }
Ejemplo n.º 4
0
        public void DeleteShopReturns404()
        {
            Shop returnedShop = null;
            var  dbMock       = new Mock <IShopRepository>();
            var  dbConf       = new Mock <IConfiguration>();

            dbMock.Setup(f => f.Get(1)).Returns(returnedShop);
            var controllerMock = new Mock <ShopsController>(dbMock.Object, dbConf.Object);

            controllerMock.Setup(f => f.isSuperAdmin(" ")).Returns(true);
            controllerMock.Setup(f => f.isShopValid(new Shop())).Returns(true);
            ShopsController controller = controllerMock.Object;

            var result = controller.DeleteShop(new SuperAdminRequest()
            {
                RootPassword = "******", Shop = new Shop()
                {
                    Id = 1
                }
            });

            Assert.Equal(404, result.StatusCode);
        }
Ejemplo n.º 5
0
 public void Setup()
 {
     mockShopiMaxRepo = new Mock <IShopiMaxRepository>();
     mockMapperRepo   = new Mock <IMapper>();
     controllerObj    = new ShopsController(mockShopiMaxRepo.Object, mockMapperRepo.Object);
 }