示例#1
0
        IStreetService GetStreetService()
        {
            var mockContext    = new Mock <IUnitOfWork>();
            var expectedStreet = new Street()
            {
                StreetId = 1, Name = "testN", Description = "testD", OSBBID = 2
            };
            var mockDbSet = new Mock <IStreetRepository>();

            mockDbSet.Setup(z =>
                            z.Find(
                                It.IsAny <Func <Street, bool> >(),
                                It.IsAny <int>(),
                                It.IsAny <int>()))
            .Returns(
                new List <Street>()
            {
                expectedStreet
            }
                );
            mockContext
            .Setup(context =>
                   context.Streets)
            .Returns(mockDbSet.Object);

            IStreetService streetService = new StreetService(mockContext.Object);

            return(streetService);
        }
示例#2
0
        public int Streets(IFormFile file, int id)
        {
            int count = 0;

            if (file.Length > 0)
            {
                var filePath = Path.GetTempFileName();
                using (var stream = System.IO.File.Create(filePath))
                {
                    file.CopyToAsync(stream);
                }
                var _Service = new StreetService();
                IEnumerable <Street> resultData = _Service.ReadCSVFile(filePath, id);
                foreach (var item in resultData)
                {
                    var value = _context.street.Where(a => a.Name.ToLower() == item.Name.ToLower() && a.PostalCodeId == item.PostalCodeId).FirstOrDefault();
                    if (value == null)
                    {
                        count = count + 1;
                        _context.street.Add(item);
                    }
                    value = null;
                }
                _context.SaveChanges();
                return(count);
            }

            return(count);
        }
        public StreetServiceTests()
        {
            _streetProvider.Setup(_ => _.ProviderName).Returns("Fake");
            _streetProviders = new List <IStreetProvider>
            {
                _streetProvider.Object
            };

            _service = new StreetService(_distributedCache.Object, _streetProviders, _pageHelper.Object, _mockPageContentFactory.Object);
        }
示例#4
0
        public WorldViewer()
        {
            countries = new List <Country>();
            cities    = new List <City>();
            streets   = new List <Street>();

            citiesService    = new CitiesService();
            countriesService = new CountriesService();
            streetService    = new StreetService();
        }
示例#5
0
        public void GetStreets_UserIsAdmin_ThrowMethodAccessException()
        {
            // Arrange
            User user = new Admin(1, "test", 1);

            SecurityContext.SetUser(user);
            var            mockUnitOfWork = new Mock <IUnitOfWork>();
            IStreetService streetService  = new StreetService(mockUnitOfWork.Object);

            // Act
            // Assert
            Assert.Throws <MethodAccessException>(() => streetService.GetStreets(0));
        }
        public async Task CreateAsync_StreetValidationSucceed_CreatesStreet()
        {
            // Arrange
            var street   = new StreetUpdateModel();
            var expected = new Street();

            var streetDAL = new Mock <IStreetDAL>();

            streetDAL.Setup(x => x.InsertAsync(street)).ReturnsAsync(expected);

            var streetService = new StreetService(streetDAL.Object);

            // Act
            var result = await streetService.CreateAsync(street);

            // Assert
            result.Should().Be(expected);
        }
        public async Task ValidateAsync_StreetExists_DoesNothing()
        {
            // Arrange
            var streetContainer = new Mock <IStreetContainer>();

            var street         = new Street();
            var streetDAL      = new Mock <IStreetDAL>();
            var streetIdentity = new Mock <IStreetIdentity>();

            streetDAL.Setup(x => x.GetAsync(streetIdentity.Object)).ReturnsAsync(street);

            var streetGetService = new StreetService(streetDAL.Object);

            // Act
            var action = new Func <Task>(() => streetGetService.ValidateAsync(streetContainer.Object));

            // Assert
            await action.Should().NotThrowAsync <Exception>();
        }
        public async Task ValidateAsync_StreetNotExists_ThrowsError()
        {
            // Arrange
            var fixture = new Fixture();
            var id      = fixture.Create <int>();

            var streetContainer = new Mock <IStreetContainer>();

            streetContainer.Setup(x => x.StreetId).Returns(id);
            var streetIdentity = new Mock <IStreetIdentity>();
            var street         = new Street();
            var streetDAL      = new Mock <IStreetDAL>();

            streetDAL.Setup(x => x.GetAsync(streetIdentity.Object)).ReturnsAsync((Street)null);

            var streetGetService = new StreetService(streetDAL.Object);

            // Act
            var action = new Func <Task>(() => streetGetService.ValidateAsync(streetContainer.Object));
            // Assert
            await action.Should().ThrowAsync <InvalidOperationException>($"Street not found by id {id}");
        }
        public StreetServiceTests()
        {
            _mockConnection
            .Setup(_ => _.Client())
            .Returns(_mockClient.Object);

            _mockClient
            .Setup(_ => _.retrieveStreetAsync(It.IsAny <FWTObjectID>()))
            .ReturnsAsync(new retrieveStreetResponse {
                FWTStreet = new FWTStreet {
                    USRN         = USRN,
                    BriefDetails = new FWTObjectBriefDetails {
                        ObjectDescription = Name
                    },
                    StreetName      = StreetName,
                    PrimaryLocality = PrimaryLocality,
                    PostTownName    = PostTownName
                }
            });

            _service = new StreetService(_mockConnection.Object);
        }
示例#10
0
        static void Main(string[] args)
        {
            try
            {
                var kernel = new StandardKernel(new ServiceModule());

                StreetService      streetService  = kernel.Get <StreetService>();
                AddressService     addressService = kernel.Get <AddressService>();
                SubdivisionService subdivService  = kernel.Get <SubdivisionService>();

                Console.WriteLine("Get All");
                StreetDTO      s  = streetService.GetAll().ToList()[0];
                AddressDTO     a  = addressService.GetAll().ToList()[0];
                SubdivisionDTO sd = subdivService.GetAll().ToList()[0];

                Console.WriteLine("Works");
                //Console.WriteLine($"{s.StreetId}  {s.StreetName}");
                //Console.WriteLine($"{a.House} {a.Latitude} {a.Longitude} {a.Serial} {a.StreetId} {a.SubdivisionId} {a.СountEntrance} {a.СountFloor}");
                //Console.WriteLine($"{sd.SubdivisionId} {sd.SubdivisionName}");

                Console.WriteLine("");
                Console.WriteLine("Get");
                Console.WriteLine("Works");

                //s = streetService.Get(1);
                //a = addressService.Get(1);
                //sd = subdivService.Get(1);

                //Console.WriteLine($"{s.StreetId}  {s.StreetName}");
                //Console.WriteLine($"{a.House} {a.Latitude} {a.Longitude} {a.Serial} {a.StreetId} {a.SubdivisionId} {a.СountEntrance} {a.СountFloor}");
                //Console.WriteLine($"{sd.SubdivisionId} {sd.SubdivisionName}");

                Console.WriteLine("");
                Console.WriteLine("Add");
                Console.WriteLine("Works");

                s = new StreetDTO()
                {
                    StreetName = "Тестовая Улица 1"
                };
                a = new AddressDTO()
                {
                    House = "TestAddress1", Latitude = decimal.Zero, Longitude = decimal.Zero, Serial = "Test Serial1", StreetId = streetService.GetAll().Last().StreetId, SubdivisionId = subdivService.GetAll().Last().SubdivisionId, СountEntrance = 0, СountFloor = 0
                };
                sd = new SubdivisionDTO()
                {
                    SubdivisionName = "SubDiv Test1"
                };

                //Console.WriteLine(streetService.Add(s));
                //Console.WriteLine(addressService.Add(a).House);
                //Console.WriteLine(a.House);
                //Console.Write(addressService.GetAll().Where(g => g.House == a.House).FirstOrDefault().AddressId);
                //Console.WriteLine(subdivService.Add(sd));


                Console.WriteLine("");
                Console.WriteLine("Update");
                Console.WriteLine("Address update ?");
                //streetService.Update(new StreetDTO() { StreetId = streetService.GetAll().Last().StreetId, StreetName = "Updated Street" });

                //addressService.Update(new AddressDTO() { AddressId = addressService.GetAll().Last().AddressId, House = "Updated Address" });

                //subdivService.Update(new SubdivisionDTO() { SubdivisionId = subdivService.GetAll().Last().SubdivisionId, SubdivisionName = "Updated SubDiv" });

                //Console.WriteLine(streetService.GetAll().Last().StreetName);
                //Console.WriteLine(addressService.GetAll().Last().House);
                //Console.WriteLine(subdivService.GetAll().Last().SubdivisionName);


                Console.WriteLine("");
                Console.WriteLine("Delete");

                Console.WriteLine(streetService.Delete(streetService.GetAll().Last()).StreetName);
                Console.WriteLine(addressService.Delete(addressService.GetAll().Last()).House);
                Console.WriteLine(subdivService.Delete(subdivService.GetAll().Last()).SubdivisionName);



                Console.ReadKey();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#11
0
 /// <summary>
 /// Creates a new street controller.
 /// </summary>
 /// <param name="streetService">The street service.</param>
 /// <param name="areaService">The area service.</param>
 public StreetController(StreetService streetService, AreaService areaService)
 {
     _streetService = streetService;
     _areaService   = areaService;
 }
示例#12
0
 /// <summary>
 /// Creates a new house controller.
 /// </summary>
 /// <param name="houseService">The house service.</param>
 /// <param name="streetService">The street service.</param>
 public HouseController(HouseService houseService, StreetService streetService)
 {
     _houseService  = houseService;
     _streetService = streetService;
 }
示例#13
0
 public StreetController()
 {
     _streetService = new StreetService();
 }