Ejemplo n.º 1
0
        public void GetUnitReturnsCorrectItemFromRepository()
        {
            // Arrange
            var unit = new Unit { UnitId = 222, UnitName = "Laptop Computer", UnitAddress = "Electronics" };
            var repo = new StubIUnitRepository { GetByIdInt32 = id => unit };
            var controller = new UnitController(repo);

            // Act
            var result = controller.Get(222);

            // Assert
            Xunit.Assert.Same(unit, result);
        }
Ejemplo n.º 2
0
        public void GetProductsByCategoryFiltersByCategory()
        {
            var units = new List<UnitTestWithNinject.Models.Unit> {
                new Unit { UnitId=111, UnitName="castle", UnitAddress="ina castle" },
                new Unit { UnitId=112, UnitName="Apt 56", UnitAddress="a apt block" },
                new Unit { UnitId=113, UnitName="house on hill", UnitAddress="hill" },
                new Unit { UnitId=114, UnitName="my shed", UnitAddress="out back" },
                new Unit { UnitId=115, UnitName="hole", UnitAddress="down a hole" },
                new Unit { UnitId=226, UnitName="tree house", UnitAddress="up a tree" }
            };
            var repo = new StubIUnitRepository { GetUnits = () => units };
            var controller = new UnitController(repo);

            var result = controller.GetUnitsByAddress("hill").ToList();

            Xunit.Assert.Same(units[2], result[0]);
        }
Ejemplo n.º 3
0
        public void GetUnitThrowsWhenRepositoryReturnsNull()
        {
            var repo = new StubIUnitRepository
            {
                GetByIdInt32 = id => null
            };
            var controller = new UnitController(repo);

            Xunit.Assert.Throws<HttpResponseException>(() => controller.Get(1));
        }