Ejemplo n.º 1
0
        public BeerControllerTest()
        {
            var config = new ConfigurationBuilder().AddJsonFile(@"C:\Projects\BeerDemo\TestBeerWebAPI\test_appsettings.json").Build();

            _databaseService = new DatabaseService(config);
            _beerController  = new BeerController(_databaseService);
        }
Ejemplo n.º 2
0
        public void TestCreateNotNull()
        {
            // Arrange
            BeerController controller = new BeerController();

            // Act
            ActionResult result = controller.Create() as ActionResult;

            // Assert
            Assert.IsNotNull(result);
        }
Ejemplo n.º 3
0
        public void TestEditNotNull()
        {
            // Arrange
            BeerController controller = new BeerController();

            // Act
            ActionResult result = controller.Edit(5) as ActionResult;

            // Assert
            Assert.IsNotNull(result);
        }
Ejemplo n.º 4
0
        public void BeerIndex()
        {
            // Arrange
            BeerController controller = new BeerController();

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
 public void Test_Get_Index()
 {
     using (var cluster = new Cluster())
     {
         using (var bucket = cluster.OpenBucket("beer-sample"))
         {
             var controller = new BeerController(new BeerRepository(bucket));
             var result     = (ViewResult)controller.Index();
             var beers      = result.Model as IEnumerable <dynamic>;
             Assert.AreEqual(10, beers.Count());
         }
     }
 }
Ejemplo n.º 6
0
        public void GetSearchErrorMessage()
        {
            var mockRequestModel = new Request();

            var mockBeerProvide = new Moq.Mock <IBeerProvider>();

            var controller = new BeerController(mockBeerProvide.Object);

            IHttpActionResult actionResult = controller.SearchBeers(mockRequestModel);

            Assert.IsNotNull(actionResult);
            Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult));
        }
Ejemplo n.º 7
0
        public void GetReturnsErrorMessage()
        {
            var id = string.Empty;

            var mockBeerProvide = new Moq.Mock <IBeerProvider>();

            var controller = new BeerController(mockBeerProvide.Object);

            IHttpActionResult actionResult = controller.GetBeer(id);

            Assert.IsNotNull(actionResult);
            Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult));
        }
        public void Test_Get_Details()
        {
            const string id = "21st_amendment_brewery_cafe-bitter_american";

            using (var cluster = new Cluster())
            {
                using (var bucket = cluster.OpenBucket("beer-sample"))
                {
                    var controller = new BeerController(new BeerRepository(bucket));
                    var result     = (ViewResult)controller.Details(id);
                    var beer       = result.Model as Beer;
                    Assert.IsNotNull(beer);
                }
            }
        }
 public void Test_Create()
 {
     using (var cluster = new Cluster())
     {
         using (var bucket = cluster.OpenBucket("beer-sample"))
         {
             bucket.Remove("skunky_beer");
             var controller = new BeerController(new BeerRepository(bucket));
             var result     = (RedirectToRouteResult)controller.Create(new Beer {
                 Name = "skunky beer"
             });
             Assert.IsNotNull(result);
         }
     }
 }
Ejemplo n.º 10
0
        public void GetBeerReturnResult(string id)
        {
            var mockBeerModel = new Beer();

            var mockBeerProvide = new Moq.Mock <IBeerProvider>();

            var controller = new BeerController(mockBeerProvide.Object);

            mockBeerProvide.Setup(x => x.GetBeer(id)).Returns(mockBeerModel);
            //Act
            IHttpActionResult actionResult = controller.GetBeer(id);

            //Assert
            Assert.IsNotNull(actionResult);
            Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <Beer>));
        }
Ejemplo n.º 11
0
        public void TestGetBeersByName_ShouldReturnMultipleBeers()
        {
            string testName = "sco";

            //Getting beers for test Name
            PunkApi api      = new PunkApi();
            var     apiBeers = api.GetBeersByName(testName);

            //Getting beers using Controller
            BeerController controller       = new BeerController();
            var            controllerResult = controller.Get(testName);

            ////Deserializing
            //var controllerBeers = JsonConvert.DeserializeObject<List<BeerDTO>>(controllerResult.ToString());

            //Assert.AreEqual(apiBeers.Count, controllerBeers.Count);
        }
        public void Test_Edit()
        {
            const string id = "21st_amendment_brewery_cafe-amendment_pale_ale";

            using (var cluster = new Cluster())
            {
                using (var bucket = cluster.OpenBucket("beer-sample"))
                {
                    var controller = new BeerController(new BeerRepository(bucket));
                    var get        = bucket.GetDocument <Beer>(id);
                    var beer       = get.Document.UnWrap();
                    beer.Ibu = 3.8m;
                    var result = (RedirectToRouteResult)controller.Edit(id, get.Content);
                    Assert.IsNotNull(result);
                }
            }
        }
Ejemplo n.º 13
0
        public void PutBeerOk()
        {
            var            logicMock  = new Mock <IBeerLogic>(MockBehavior.Strict);
            BeerController controller = new BeerController(logicMock.Object);
            BeerModel      beerModel  = new BeerModel()
            {
                BeerFactoryId = 1,
                Description   = "Prueba",
                Name          = "Prueba",
                Qualification = 1
            };

            logicMock.Setup(x => x.Update(It.IsAny <Beer>()));

            var result   = controller.Put(1, beerModel);
            var okResult = result as OkObjectResult;

            logicMock.VerifyAll();
        }
Ejemplo n.º 14
0
        public void GetSearchReturnResult(string queryRequest)
        {
            var mockRequestModel = new Request {
                query = queryRequest
            };

            var mockBeersModel = new Beers();

            var mockBeerProvide = new Moq.Mock <IBeerProvider>();

            mockBeerProvide.Setup(x => x.SearchBeers(mockRequestModel)).Returns(mockBeersModel);
            var controller = new BeerController(mockBeerProvide.Object);

            //Act
            IHttpActionResult actionResult = controller.SearchBeers(mockRequestModel);

            //Assert
            Assert.IsNotNull(actionResult);
            Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <Beers>));
        }
Ejemplo n.º 15
0
        public void PostBeerOk()
        {
            var            logicMock  = new Mock <IBeerLogic>(MockBehavior.Strict);
            BeerController controller = new BeerController(logicMock.Object);
            BeerModel      beerModel  = new BeerModel()
            {
                BeerFactoryId = 1,
                Description   = "Prueba",
                Name          = "Prueba",
                Qualification = 1
            };

            logicMock.Setup(x => x.Add(It.IsAny <Beer>(), 1)).Returns(It.IsAny <Beer>());

            var result   = controller.Post(beerModel);
            var okResult = result as OkObjectResult;
            var value    = okResult.Value as Beer;

            logicMock.VerifyAll();
        }
Ejemplo n.º 16
0
        public void PutBeerNotExist()
        {
            var            logicMock  = new Mock <IBeerLogic>(MockBehavior.Strict);
            BeerController controller = new BeerController(logicMock.Object);
            BeerModel      beerModel  = new BeerModel()
            {
                BeerFactoryId = 1,
                Description   = "Prueba",
                Name          = "Prueba",
                Qualification = 1
            };

            logicMock.Setup(x => x.Update(It.IsAny <Beer>())).Throws(new Exception());

            var result   = controller.Put(1, beerModel);
            var okResult = result as NotFoundObjectResult;

            logicMock.VerifyAll();

            Assert.AreEqual(404, okResult.StatusCode);
        }
Ejemplo n.º 17
0
        public BeerControllerTests()
        {
            repo = Substitute.For <IBeerRepository>();

            underTest = new BeerController(repo);
        }
Ejemplo n.º 18
0
 public BeerControllerTest()
 {
     BeerController = new BeerController();
 }
Ejemplo n.º 19
0
 public BeerControllerTests()
 {
     _beerBusiness   = A.Fake <IBeerBusiness>();
     _beerController = new BeerController(_beerBusiness);
 }