示例#1
0
        internal void AddLocations()
        {
            Console.WriteLine("Creating Locations");

            using var ctx = new VendorContext();

            LocationService locServ = new LocationService(ctx);

            locServ.Create("The Mojave Wasteland");
            locServ.Create("The Capital Warehouse Store");
            locServ.Create("Diamond City Goods");

            Console.WriteLine("Locations Created");
        }
示例#2
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ILocationService, ILocationRepository>();
            var model         = new ApiLocationServerRequestModel();
            var validatorMock = new Mock <IApiLocationServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiLocationServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new LocationService(mock.LoggerMock.Object,
                                              mock.MediatorMock.Object,
                                              mock.RepositoryMock.Object,
                                              validatorMock.Object,
                                              mock.DALMapperMockFactory.DALLocationMapperMock,
                                              mock.DALMapperMockFactory.DALTweetMapperMock,
                                              mock.DALMapperMockFactory.DALUserMapperMock);

            CreateResponse <ApiLocationServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiLocationServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <LocationCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
        public async Task <ActionResult> Create(CreateLocVM model)
        {
            if (ModelState.IsValid)
            {
                Locations newloc = new Locations()
                {
                    LocName     = model.LocationName,
                    Notes       = model.Notes,
                    DateCreated = DateTimeOffset.Now
                };

                //try
                //{
                //    await _locationService.Create(newloc);

                //    TempData.Add("SuccessMsg", "The new provider was created successfully!");
                //}
                //catch (Exception ex)
                //{
                //    // Add message to the user
                //    Console.WriteLine("An error has occurred. Message: " + ex.ToString());
                //    throw;
                //}
                await _locationService.Create(newloc);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public IHttpActionResult Create(LocationDTO dto)
        {
            var model = _mapper.Map <LocationModel>(dto);

            model = _locationService.Create(model);

            return(Ok(model.Id));
        }
示例#5
0
        public async Task <ActionResult> Create(LocationCreateDTO Location)
        {
            var result = await _LocationService.Create(Location);

            return(CreatedAtAction(
                       "GetById",
                       new { id = result.LocationId },
                       result));
        }
示例#6
0
        public Location CreateVerify(
            ILocationRepository locationRepository = null,
            ILocationValidator validator           = null)
        {
            locationRepository ??= new Mock <ILocationRepository>().Object;
            validator ??= new Mock <ILocationValidator>().Object;

            var service  = new LocationService(locationRepository, validator) as ILocationService;
            var location = _locationEntityTestHelper.ValidLocation();

            service.Create(location);
            return(location);
        }
示例#7
0
        public void Create_WithLocationParameter_ShouldCallILocationValidatorsDefaultValidationMethodOnTime()
        {
            Mock <ILocationRepository> locationRepositoryMock = new Mock <ILocationRepository>();
            Mock <ILocationValidator>  locationValidatorMock  = new Mock <ILocationValidator>();
            LocationService            locationService        = new LocationService(locationRepositoryMock.Object, locationValidatorMock.Object);
            Location location = new Location
            {
                Name = "Hyd"
            };

            locationService.Create(location);
            locationValidatorMock.Verify(lm => lm.DefaultValidation(location), Times.Once);
        }
示例#8
0
            public async Task Sucess_LocationService_Create()
            {
                //Arrange
                mockedDao.Invocations.Clear();
                mockedDao.Setup(s => s.AddAsync(It.IsAny <Location>()));

                //Act
                service = new LocationService(mockedUnitOfWork.Object, mockedDao.Object);
                int locationId = await service.Create(this.location);

                //Assert
                Assert.AreEqual(2, locationId);
                mockedDao.Verify(s => s.AddAsync(It.IsAny <Location>()), Times.Once);
            }
        public void NullContractInvalid()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            validatorFactory.Setup(x => x.IsValid(It.IsAny<object>(), It.IsAny<IList<IRule>>())).Returns(false);

            // Act
            service.Create(null);
        }
示例#10
0
        public void NullContractInvalid()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            validatorFactory.Setup(x => x.IsValid(It.IsAny <object>(), It.IsAny <IList <IRule> >())).Returns(false);

            // Act
            service.Create(null);
        }
示例#11
0
        public void InvalidContractNotSaved()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var contract = new EnergyTrading.MDM.Contracts.Sample.Location();

            validatorFactory.Setup(x => x.IsValid(It.IsAny <object>(), It.IsAny <IList <IRule> >())).Returns(false);

            // Act
            service.Create(contract);
        }
        public void InvalidContractNotSaved()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var contract = new EnergyTrading.MDM.Contracts.Sample.Location();

            validatorFactory.Setup(x => x.IsValid(It.IsAny<object>(), It.IsAny<IList<IRule>>())).Returns(false);

            // Act
            service.Create(contract);
        }
示例#13
0
        public void LocationCreation(LocationService ls)
        {
            Console.Clear();
            Console.WriteLine("Enter address for the location: ");
            string address = Console.ReadLine();

            Console.WriteLine("Enter Municipality ID where the municipality is located: ");
            int municipalityid = int.Parse(Console.ReadLine());

            var AddLocation = new Location()
            {
                Address        = address,
                MunicipalityId = municipalityid
            };

            ls.Create(AddLocation);

            Console.WriteLine("Location added!\n");
        }
示例#14
0
        public void createLocation(LocationService ls)
        {
            Console.Clear();
            Console.WriteLine("Type in the address for the location: ");
            string address = Console.ReadLine();

            Console.WriteLine("Type in the Municipality ID for the municipality the location is located in: ");
            int municipalityid = int.Parse(Console.ReadLine());

            var LocationAdd = new Location()
            {
                Address        = address,
                MunicipalityID = municipalityid
            };

            ls.Create(LocationAdd);

            Console.WriteLine("Location succesfully added!\n");
        }
示例#15
0
        public IActionResult Update([FromBody] LocationViewModel locationViewModel)
        {
            try
            {
                if (locationViewModel.Id == null || locationViewModel == null)
                {
                    return(BadRequest());
                }

                string message   = string.Empty;
                var    isUpdated = LocationService.Create(locationViewModel);
                message = isUpdated ? "Updated" : "Not Updated";

                return(Ok(new { message = message }));
            }
            catch
            {
                return(StatusCode(500));
            }
        }
        public void AddLocationTest()
        {
            string locationName = "NewLocation";

            var options = new DbContextOptionsBuilder <VendorContext>()
                          .UseInMemoryDatabase(databaseName: "TestDB")
                          .Options;

            // Save something to imdb
            using (var ctx = new VendorContext(options))
            {
                LocationService locationService = new LocationService(ctx);
                locationService.Create(locationName);
            }

            using (var ctx = new VendorContext(options))
            {
                Location location = ctx.Locations.FirstOrDefault(l => l.Name == locationName);
                Assert.NotNull(location);
            }
        }
示例#17
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ILocationRepository>();
            var model = new ApiLocationRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Location>())).Returns(Task.FromResult(new Location()));
            var service = new LocationService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.LocationModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLLocationMapperMock,
                                              mock.DALMapperMockFactory.DALLocationMapperMock,
                                              mock.BOLMapperMockFactory.BOLTweetMapperMock,
                                              mock.DALMapperMockFactory.DALTweetMapperMock,
                                              mock.BOLMapperMockFactory.BOLUserMapperMock,
                                              mock.DALMapperMockFactory.DALUserMapperMock);

            CreateResponse <ApiLocationResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.LocationModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiLocationRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Location>()));
        }
示例#18
0
        // Genererer et antal tilfældige lokationer
        public void GenerateLocation(LocationService ls, int number = 100)
        {
            // Clears the database of Locations
            var myLocation = ls.Get();

            foreach (var i in myLocation)
            {
                ls.Remove(i);
            }

            for (int i = 1; i < (number + 1); i++)
            {
                var temp = random.Next(Municipalities.Count);

                var location = new Location()
                {
                    Address        = "Vejnavn " + i.ToString(),
                    MunicipalityID = Municipalities[temp]
                };

                ls.Create(location);
            }
        }
 public int CreateLocation(string accessId, LocationDTO LocationDTO)
 {
     try
     {
         return(LocationService.Create(LocationDTO));
     }
     catch (TimeoutException)
     {
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.RequestTimeout)
         {
             Content      = new StringContent("An error occurred, please try again or contact the administrator."),
             ReasonPhrase = "Critical Exception"
         });
     }
     catch (Exception)
     {
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
         {
             Content      = new StringContent("An error occurred, please try again or contact the administrator."),
             ReasonPhrase = "Critical Exception"
         });
     }
 }
示例#20
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <ILocationService, ILocationRepository>();

            var model = new ApiLocationServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Location>())).Returns(Task.FromResult(new Location()));
            var service = new LocationService(mock.LoggerMock.Object,
                                              mock.MediatorMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.LocationModelValidatorMock.Object,
                                              mock.DALMapperMockFactory.DALLocationMapperMock,
                                              mock.DALMapperMockFactory.DALTweetMapperMock,
                                              mock.DALMapperMockFactory.DALUserMapperMock);

            CreateResponse <ApiLocationServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.LocationModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiLocationServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Location>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <LocationCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
示例#21
0
        public void ValidContractIsSaved()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var location = new Location();
            var contract = new EnergyTrading.MDM.Contracts.Sample.Location();

            validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.MDM.Contracts.Sample.Location>(), It.IsAny <IList <IRule> >())).Returns(true);
            mappingEngine.Setup(x => x.Map <EnergyTrading.MDM.Contracts.Sample.Location, Location>(contract)).Returns(location);

            // Act
            var expected = service.Create(contract);

            // Assert
            Assert.AreSame(expected, location, "Location differs");
            repository.Verify(x => x.Add(location));
            repository.Verify(x => x.Flush());
        }
        public void ValidContractIsSaved()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var location = new Location();
            var contract = new EnergyTrading.MDM.Contracts.Sample.Location();

            validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Location>(), It.IsAny<IList<IRule>>())).Returns(true);
            mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.Location, Location>(contract)).Returns(location);

            // Act
            var expected = service.Create(contract);

            // Assert
            Assert.AreSame(expected, location, "Location differs");
            repository.Verify(x => x.Add(location));
            repository.Verify(x => x.Flush());
        }
 public Location Create(Location entity)
 => _locationService.Create(entity);