コード例 #1
0
        public void TestGetCitiesWithoutResult()
        {
            DynamicMock dynamicMock = new DynamicMock(typeof(LocationsManager));

            dynamicMock.SetReturnValue("GetCities", new List <City>());

            LocationsManager locationsManager = (LocationsManager)dynamicMock.MockInstance;
            LocationServices locationServices = new LocationServices(locationsManager);

            Assert.AreEqual(0, locationServices.GetCities().Count);
        }
コード例 #2
0
        public void TestGetCitiesWhithResults()
        {
            List <City> cities = new List <City>
            {
                new City(),
                new City(),
                new City()
            };

            DynamicMock dynamicMock = new DynamicMock(typeof(LocationsManager));

            dynamicMock.SetReturnValue("GetCities", cities);

            LocationsManager locationsManager = (LocationsManager)dynamicMock.MockInstance;
            LocationServices locationServices = new LocationServices(locationsManager);

            Assert.AreEqual(3, locationServices.GetCities().Count);
        }
コード例 #3
0
        public void TestDeleteCity()
        {
            List <City> cities = new List <City>();
            City        city   = new City {
                Name = "New York", DistrictId = 12
            };
            DynamicMock dynamicMock = new DynamicMock(typeof(LocationsManager));

            dynamicMock.ExpectAndReturn("AddCity", 3, city);
            dynamicMock.SetReturnValue("GetCities", cities);
            dynamicMock.Expect("DeleteCityById", 2);

            LocationsManager mocklocationManager = (LocationsManager)dynamicMock.MockInstance;
            LocationServices locationService     = new LocationServices(mocklocationManager);

            locationService.DeleteCity(2);
            Assert.AreEqual(3, locationService.AddCity(city));
            Assert.AreEqual(0, locationService.GetCities().Count);
        }
コード例 #4
0
        public void TestUpdateCity()
        {
            City city = new City {
                Name = "Pekin", DistrictId = 12
            };
            List <City> cities = new List <City> {
                city
            };

            DynamicMock mockLocationsManager = new DynamicMock(typeof(LocationsManager));

            mockLocationsManager.ExpectAndReturn("AddCity", 3, city);
            mockLocationsManager.SetReturnValue("GetCities", cities);
            mockLocationsManager.ExpectAndReturn("UpdateCity", true, city);


            LocationsManager mocklocationManager = (LocationsManager)mockLocationsManager.MockInstance;
            LocationServices locationService     = new LocationServices(mocklocationManager);

            Assert.AreEqual("Pekin", locationService.GetCities()[0].Name);
            Assert.AreEqual(true, locationService.UpdateCity(city));
        }