Пример #1
0
        public UsZipCodeDto MapToUsZipCodeDto(ZipCode z)
        {
            var zipCode = new UsZipCodeDto()
            {
                Id      = z.ZipCodeId,
                ZipCode = z.Digits,
                CityId  = z.CityId
            };

            return(zipCode);
        }
Пример #2
0
        public async Task CreateZipCodeWithNameAndId(string zipCodeDigits, int cityId)
        {
            using (var mock = AutoMock.GetLoose())
            {
                var toCreate = new UsZipCodeToCreateDto
                {
                    ZipCode = zipCodeDigits,
                    CityId  = cityId
                };
                var zipCode = new ZipCode
                {
                    Digits = zipCodeDigits,
                    CityId = cityId
                };
                var returnDto = new UsZipCodeDto
                {
                    Id      = 1,
                    ZipCode = zipCodeDigits,
                    CityId  = cityId
                };

                // Expression<Func<ZipCode, bool>> ex = z => z.CityId == d.CityId && z.Digits == d.ZipCode;
                // // would like to test with ^^this^^ but don't think I'm able to
                // mock.Mock<IUsZipCodeData>().Setup(x => x.Find(ex)).Returns(Task.FromResult(zipCode));
                var zipCodeList      = new List <ZipCode>();
                var matchingZipCodes = zipCodeList.AsEnumerable();

                mock.Mock <IMap>().Setup(x => x.MapToZipCode(It.IsAny <UsZipCodeToCreateDto>())).Returns(zipCode);
                mock.Mock <IUsZipCodeData>().Setup(x => x.FindManyAsync(It.IsAny <Expression <Func <ZipCode, bool> > >()))
                .Returns(Task.FromResult(matchingZipCodes));
                mock.Mock <IUsZipCodeData>().Setup(x => x.Add(zipCode));
                mock.Mock <IUsZipCodeData>().Setup(x => x.SaveAllAsync()).Returns(Task.FromResult(true));
                mock.Mock <IMap>().Setup(x => x.MapToUsZipCodeDto(zipCode)).Returns(returnDto);

                var cls      = mock.Create <UtilityRepo>();
                var expected = 1;
                var actual   = await cls.CreateZipCodeAsync(zipCodeDigits, cityId);

                Assert.Equal(expected, actual);
            }
        }