public void GetZipInfo_ReturnsZipCodeInfo() { // Arrange var mockZipCodeRepository = Substitute.For<IZipCodeRepository>(); var zipCode = new ZipCode { City = "LINCOLN PARK", State = new State { Abbreviation = "NJ" }, Zip = "07035" }; mockZipCodeRepository.GetByZip("07035").Returns(zipCode); var manager = new GeoManager(mockZipCodeRepository); // Act var actual = manager.GetZipInfo("07035"); // Assert Assert.Equal(zipCode.City, actual.City); Assert.Equal(zipCode.State.Abbreviation, actual.State); }
public void test_zip_code_retrieval() { // we gona use moq here, the job is // to moq up any dependencies in Geomanager // in geo manager getzipcodeinfo we have zip code repo dependences. // which is a tpe of IZipCodeRepo and now as this is a class wide variable //we can send it in using one of ctor but instead of using live zip code repo //which is designed to hit the database, we need to create a test class //a test implementation of IZipCodeRepo that has its own GetByZip member and // instructed to retrun a zipcode entity, which will be used by new ZipCodeData Operation //however rather than writing a test implementation of that calss Mocking came in //1. So first thing is to create a mock for IZipCodeRepo Mock<IZipCodeRepository> mockZipCodeRepo = new Mock<IZipCodeRepository>(); //2. Remember zipcode repo has GetByZip which is designed to return a zipcdoe entity // the fake one needs to also know what to retrun but we are going to it ahead of time //by creating a mocked up entity, ZipCode zipCode = new ZipCode() { City = "Lincoln Park", State = new State() { Abbreviation = "NJ" }, Zip = "07035" }; //3. Now we have to set up the mock. So we are going to tell mock // when you enconouter the following member of IZipCodeRepo that receive the // the following information, return something like this mockZipCodeRepo.Setup(obj => obj.GetByZip("07035")).Returns(zipCode); //4. Now unit test needs to instantiate the GeoManager calss // We can do this by defining the GeoManager var but it would be better //to be explicit when we are dealing with any thing that implements interface // and define as interface in this case as service ocntract // Now our ctor will be the one where we can send in our own implementation //of zipcode repo. In this case that implementaion in object property of //mock zip code instance. IGeoService geoService = new GeoManager(mockZipCodeRepo.Object); //5. Now we have instance of Geomanager class we can call GetZipCode operation ZipCodeData data = geoService.GetZipInfo("07035"); Assert.IsTrue(data.City.ToUpper() == "LINCOLN PARK"); Assert.IsTrue(data.State == "NJ"); }
public void Return_corresponding_zipcode_given_a_zip() { var zipCode = new ZipCode() { City = "LINCOLN PARK", State = new State() {Abbreviation = "NJ"}, Zip = "07035" }; var zipRepository = Substitute.For<IZipCodeRepository>(); zipRepository.GetByZip("07035").Returns(zipCode); var manager = new GeoManager(zipCodeRepository: zipRepository); var data = manager.GetZipInfo("07035"); data.City.Should().Be("LINCOLN PARK"); data.State.Should().Be("NJ"); data.ZipCode.Should().Be("07035"); }
public void TestZipCodeRetrieval() { Mock<IZipCodeRepository> mockZipCodeRepository = new Mock<IZipCodeRepository>(); ZipCode zipCode = new ZipCode() { City = "LINCOLN PARK", State = new State() { Abbreviation = "NJ"}, Zip = "07035" }; mockZipCodeRepository.Setup(i => i.GetByZip("07035")).Returns(zipCode); IGeoService geoService = new GeoManager(mockZipCodeRepository.Object); var data = geoService.GetZipInfo("07035"); Assert.IsTrue(data.City.ToUpper() == "LINCOLN PARK"); Assert.IsTrue(data.State == "NJ"); }
public void test_zip_code_retrieval() { Mock<IZipCodeRepository> mockZipCodeRepository = new Mock<IZipCodeRepository>(); ZipCode zipCode = new ZipCode() { City = "Lincoln Park", State = new State() { Abbreviation = "NJ" }, Zip = "07035" }; mockZipCodeRepository.Setup(obj => obj.GetByZip("07035")).Returns(zipCode); //-- IGeoService geoService = new GeoManager(mockZipCodeRepository.Object); ZipCodeData data = geoService.GetZipInfo("07035"); Assert.IsTrue(data.City == "Lincoln Park"); Assert.IsTrue(data.State == "NJ"); }
public void Check_Get_Zip_Data() { Mock<IZipCodeRepository> moqZipRepository = new Mock<IZipCodeRepository>(); ZipCode zipCode = new ZipCode { Zip = "122001", City = "Gurgaon", State = new State { Abbreviation = "HRY" } }; moqZipRepository.Setup(obj => obj.GetByZip("122001")).Returns(zipCode); IGeoService geoService = new GeoManager(moqZipRepository.Object); ZipCodeData zipCodeData = geoService.GetZipInfo("122001"); Assert.IsTrue(zipCodeData.City.ToUpper().Equals("GURGAON")); Assert.IsTrue(zipCodeData.State.ToUpper().Equals("HRY")); }
public void PushZip(string zip) { IZipCodeRepository stateFulZipCodeRepo = new ZipCodeRepository(); this._StateFulZipCodeEntity = stateFulZipCodeRepo.GetByZip(zip); }
public void PushZip(string zip) { IZipCodeRepository zipCodeRepository = new ZipCodeRepository(); _ZipCodeEntity = zipCodeRepository.GetByZip(zip); }