コード例 #1
0
ファイル: UnitTest1.cs プロジェクト: elennon/apiTesting
        public void GetAllUnitsReturnsEverythingInRepository()
        {
            // Arrange
            var allUnits = 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 UnitTestWithNinject.Fakes.StubIUnitRepository
            {
                GetUnits = () => allUnits//.AsQueryable()
            };
            var controller = new UnitController(repo);

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

            // Assert
            Xunit.Assert.Same(allUnits, result);
            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(result);
            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(6, result.ToList().Count);
        }
コード例 #2
0
ファイル: UnitTest1.cs プロジェクト: elennon/apiTesting
        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);
        }
コード例 #3
0
ファイル: UnitTest1.cs プロジェクト: elennon/apiTesting
        public void GetUnitThrowsWhenRepositoryReturnsNull()
        {
            var repo = new StubIUnitRepository
            {
                GetByIdInt32 = id => null
            };
            var controller = new UnitController(repo);

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