public void GetAddressByIdSuccessTest() { int id = 1; string Address1 = "Test"; string Address2 = "Test"; string City = "Test"; string ZipCode = "71000"; bool isDeleted = false; int AddressTypeId = 1; int CreatedByUserId = 1; DateTime DateCreated = DateTime.Now; DateTime DateModified = DateTime.Now; var addressDto = new AddressDto { AddressId = id, Address1 = Address1, Address2 = Address2, City = City, ZipCode = ZipCode, AddressTypeId = AddressTypeId, CreatedByUserId = CreatedByUserId, IsDeleted = isDeleted, DateCreated = DateCreated, DateModified = DateModified }; var data = new List <Address> { new Address { AddressId = 0 }, new Address { }, new Address { }, }.AsQueryable(); var mockSet = new Mock <DbSet <Address> >(); mockSet.As <IQueryable <Address> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Address> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Address> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Address> >().Setup(m => m.GetEnumerator()).Returns(() => data.GetEnumerator()); var mockRepo = new Mock <IkarusContext>(); mockRepo.Setup(x => x.Address).Returns(mockSet.Object); var addressRepository = new AddressRepository(mockRepo.Object); var result = addressRepository.GetAddressById(0); Assert.IsType <AddressDto>(result); }
public void GetAddressSuccessfully() { var content = File.ReadAllText("../../Fixtures/address_get_by_id.json"); var client = GetMockClient(content); var repo = new AddressRepository(client.Object); var address = repo.GetAddressById("07ed45e5-bb9d-459f-bb7b-a02ecb38f443"); client.VerifyAll(); Assert.IsNotNull(address); Assert.AreEqual("07ed45e5-bb9d-459f-bb7b-a02ecb38f443", address.Id); }
public void GetAddressSuccessfully() { var content = File.ReadAllText("../../Fixtures/address_get_by_id.json"); var client = GetMockClient(content); var repo = new AddressRepository(client.Object); var resp = repo.GetAddressById("07ed45e5-bb9d-459f-bb7b-a02ecb38f443"); client.VerifyAll(); Assert.IsNotNull(resp); var address = JsonConvert.DeserializeObject <IDictionary <string, object> >(JsonConvert.SerializeObject(resp.Values.First())); Assert.AreEqual("07ed45e5-bb9d-459f-bb7b-a02ecb38f443", (string)address["id"]); }
public void GetAddressByIdThrowExceptionFailureTest() { int id = 1; string Address1 = "Test"; string Address2 = "Test"; string City = "Test"; string ZipCode = "71000"; bool isDeleted = false; int AddressTypeId = 1; int CreatedByUserId = 1; DateTime DateCreated = DateTime.Now; DateTime DateModified = DateTime.Now; var addressDto = new AddressDto { AddressId = id, Address1 = Address1, Address2 = Address2, City = City, ZipCode = ZipCode, AddressTypeId = AddressTypeId, CreatedByUserId = CreatedByUserId, IsDeleted = isDeleted, DateCreated = DateCreated, DateModified = DateModified }; var mockRepo = new Mock <IkarusContext>(); mockRepo.Setup(x => x.Address).Throws <Exception>(); var addressRepository = new AddressRepository(mockRepo.Object); try { var result = addressRepository.GetAddressById(0); } catch (Exception e) { Assert.IsType <Exception>(e); } }