public void DeleteShouldReturnTrueIfRepositoryThrowsNoExceptions() { // Arrange var mock = new Mock <IDeliveryPersonRepository>(); var mockId = Guid.NewGuid(); Repository = mock.Object; Service = new DeliveryPersonService(Repository); // Act var result = Service.Delete(mockId); // Assert Assert.IsTrue(result); }
public void AddShouldReturnTrueIfRepositoryHasNoExceptions() { // Arrange var mock = new Mock <IDeliveryPersonRepository>(); Repository = mock.Object; Service = new DeliveryPersonService(Repository); var mockCustomer = Builder <DeliveryPersonAddModel> .CreateNew().Build(); // Act var result = Service.Add(mockCustomer); // Assert Assert.IsTrue(result); }
public void EditShouldReturnTrueIfRepositoryThrowsNoExceptions() { // Arrange var mock = new Mock <IDeliveryPersonRepository>(); Repository = mock.Object; Service = new DeliveryPersonService(Repository); var mockDPerson = Builder <DeliveryPersonEditModel> .CreateNew().Build(); // Act var result = Service.Edit(mockDPerson); // Assert Assert.IsTrue(result); }
public void ListDeliveryPersonsShouldReturnEmptyEnumerableIfRepositoryThrowsExceptions() { // Arrange var mock = new Mock <IDeliveryPersonRepository>(); mock.Setup <IEnumerable <DeliveryPerson> >(_ => _.List(0)) .Throws <Exception>(); Repository = mock.Object; Service = new DeliveryPersonService(Repository); // Act var result = Service.List(0); // Assert Assert.AreEqual(0, result.Count()); }
public void AddShouldReturnFalseIfRepositoryHasExceptions() { // Arrange var mock = new Mock <IDeliveryPersonRepository>(); mock.Setup(_ => _.CreateNewDeliveryPerson(It.IsAny <DeliveryPerson>())) .Throws <Exception>(); Repository = mock.Object; Service = new DeliveryPersonService(Repository); var mockDPerson = Builder <DeliveryPersonAddModel> .CreateNew().Build(); // Act var result = Service.Add(mockDPerson); // Assert Assert.IsFalse(result); }
public void DeleteShouldReturnFalseIfRepositoryThrowsExceptions() { // Arrange var mock = new Mock <IDeliveryPersonRepository>(); var mockId = Guid.NewGuid(); mock.Setup(_ => _.DeleteDeliveryPersonById(mockId)) .Throws <Exception>(); Repository = mock.Object; Service = new DeliveryPersonService(Repository); // Act var result = Service.Delete(mockId); // Assert Assert.IsFalse(result); }
public void EditShouldReturnFalseIfRepositoryThrowsExceptions() { // Arrange var mock = new Mock <IDeliveryPersonRepository>(); mock.Setup(_ => _.UpdateDeliveryPersonDetails(It.IsAny <DeliveryPerson>())) .Throws <Exception>(); Repository = mock.Object; Service = new DeliveryPersonService(Repository); var mockCustomer = Builder <DeliveryPersonEditModel> .CreateNew().Build(); // Act var result = Service.Edit(mockCustomer); // Assert Assert.IsFalse(result); }
public void GetShouldReturnNullIfRepositoryThrowsExceptions() { // Arrange var mock = new Mock <IDeliveryPersonRepository>(); var mockId = Guid.NewGuid(); mock.Setup <DeliveryPerson>(_ => _.GetDeliveryPersonById(mockId)) .Throws <Exception>(); Repository = mock.Object; Service = new DeliveryPersonService(Repository); // Act var result = Service.Get(mockId); // Assert Assert.AreEqual(null, result); }
public void ListDeliveryPersonShouldReturnTheSameDataIfRepositoryReturnsData() { // Arrange var mock = new Mock <IDeliveryPersonRepository>(); var mockData = Builder <DeliveryPerson> .CreateListOfSize(100).Build(); mock.Setup <IEnumerable <DeliveryPerson> >(_ => _.List(0)) .Returns(mockData); Repository = mock.Object; Service = new DeliveryPersonService(Repository); // Act var result = Service.List(0); var same = mockData.All(dPerson => result.Any(model => model.FirstName == dPerson.FirstName && model.LastName == dPerson.LastName)); // Assert Assert.IsTrue(same); }
public void GetShouldReturnTheSameDataIfRepositoryReturnsData() { // Arrange var mock = new Mock <IDeliveryPersonRepository>(); var mockId = Guid.NewGuid(); var mockData = Builder <DeliveryPerson> .CreateNew().Build(); mock.Setup <DeliveryPerson>(_ => _.GetDeliveryPersonById(mockId)) .Returns(mockData); Repository = mock.Object; Service = new DeliveryPersonService(Repository); // Act var result = Service.Get(mockId); bool same = mockData.FirstName == result.FirstName && mockData.LastName == result.LastName; // Assert Assert.IsTrue(same); }
public AlohaService() { LogHelper.Configure(); log = LogHelper.GetLogger(); if (!MapperInited) { try { Mapper.Initialize(cfg => { //cfg.CreateMap<ServiceDataContracts.Dish, Entities.Dish>().ReverseMap(); cfg.CreateMap <ServiceDataContracts.Dish, Entities.Dish>().ReverseMap(); cfg.CreateMap <ServiceDataContracts.DishPackageToGoOrder, Entities.DishPackageToGoOrder>() .ForMember(m => m.Dish, opt => opt.Ignore()) .ForMember(m => m.OrderToGo, opt => opt.Ignore()); cfg.CreateMap <Entities.DishPackageToGoOrder, ServiceDataContracts.DishPackageToGoOrder>() .ForMember(m => m.Dish, opt => opt.Ignore()) .ForMember(m => m.OrderToGo, opt => opt.Ignore()); cfg.CreateMap <ServiceDataContracts.DishPackageFlightOrder, Entities.DishPackageFlightOrder>() .ForMember(m => m.Dish, opt => opt.Ignore()) .ForMember(m => m.OrderFlight, opt => opt.Ignore()) .ReverseMap(); cfg.CreateMap <ServiceDataContracts.User, Entities.User>() .ForMember(m => m.UserRole, opt => opt.Ignore()) //.ForMember(m => m.OrderFlight, opt => opt.Ignore()) .ReverseMap(); /* * cfg.CreateMap<ServiceDataContracts.OrderToGo, Entities.OrderToGo>() * //.ForMember(m => m., opt => opt.Ignore()) * //.ForMember(m => m.OrderFlight, opt => opt.Ignore()) * .ReverseMap(); */ cfg.CreateMap <ServiceDataContracts.Driver, Entities.Driver>() .ReverseMap(); cfg.CreateMap <ServiceDataContracts.OrderFlight, Entities.OrderFlight>() .ForMember(m => m.AirCompany, opt => opt.Ignore()) .ForMember(m => m.ContactPerson, opt => opt.Ignore()) .ForMember(m => m.CreatedBy, opt => opt.Ignore()) .ForMember(m => m.DeliveryPlace, opt => opt.Ignore()) .ForMember(m => m.PaymentType, opt => opt.Ignore()) .ForMember(m => m.SendBy, opt => opt.Ignore()) .ForMember(m => m.WhoDeliveredPersonPerson, opt => opt.Ignore()) .ReverseMap(); cfg.CreateMap <ServiceDataContracts.OrderToGo, Entities.OrderToGo>() .ForMember(m => m.DishPackages, opt => opt.MapFrom(a => a.DishPackages.ToList())) //.ForMember(m => m.DishPackages, a=> a.MapFrom<List<Entities.DishPackageToGoOrder>, List<ServiceDataContracts.DishPackageToGoOrder>>(a.)) .ReverseMap(); cfg.CreateMap <ServiceDataContracts.OrderCustomer, Entities.OrderCustomer>() .ReverseMap(); cfg.CreateMap <ServiceDataContracts.OrderCustomerPhone, Entities.OrderCustomerPhone>() .ReverseMap(); cfg.CreateMap <ServiceDataContracts.OrderCustomerAddress, Entities.OrderCustomerAddress>() .ReverseMap(); cfg.CreateMap <ServiceDataContracts.OrderCustomerInfo, Entities.OrderCustomerInfo>() .ReverseMap(); }); //Mapper.Initialize(cfg => cfg.CreateMap<ServiceDataContracts.DishPackageFlightOrder, Entities.DishPackageFlightOrder>().ReverseMap()); //Mapper.Initialize(cfg => cfg.CreateMap<ServiceDataContracts.DishPackageToGoOrder, Entities.DishPackageToGoOrder>().ReverseMap()); //Mapper.Initialize(cfg => cfg.CreateMap<ServiceDataContracts.Dish, Entities.Dish>().ReverseMap()); //Mapper.Initialize(cfg => cfg.CreateMap<Entities.Dish, ServiceDataContracts.Dish>()); MapperInited = true; log.Debug("Mapper.Initialize ok"); } catch (Exception e) { log.Error("Mapper.Initialize error " + e.Message); } } userService = new UserService(new AlohaDb()); orderService = new OrderService(new AlohaDb()); airCompanyService = new AirCompanyService(new AlohaDb()); userGroupService = new UserGroupService(new AlohaDb()); contactPersonService = new ContactPersonService(new AlohaDb()); curierService = new CurierService(new AlohaDb()); deliveryPersonService = new DeliveryPersonService(new AlohaDb()); deliveryPlaceService = new DeliveryPlaceService(new AlohaDb()); marketingChannelService = new MarketingChannelService(new AlohaDb()); dishPackageFlightOrderService = new DishPackageFlightOrderService(new AlohaDb()); dishPackageToGoOrderService = new DishPackageToGoOrderService(new AlohaDb()); dishService = new DishService(new AlohaDb()); driverService = new DriverService(new AlohaDb()); itemLabelInfoService = new ItemLabelInfoService(new AlohaDb()); orderCustomerService = new OrderCustomerService(new AlohaDb()); orderFlightService = new OrderFlightService(new AlohaDb()); orderToGoService = new OrderToGoService(new AlohaDb()); discountService = new DiscountService(new AlohaDb()); alertService = new AlertService(new AlohaDb()); paymentService = new PaymentService(new AlohaDb()); paymentGroupService = new PaymentGroupService(new AlohaDb()); dishLogicGroupService = new DishLogicGroupService(new AlohaDb()); dishKitchenGroupService = new DishKitchenGroupService(new AlohaDb()); logItemService = new LogItemService(new AlohaDb()); orderCustomerAddressService = new OrderCustomerAddressService(new AlohaDb()); orderCustomerPhoneService = new OrderCustomerPhoneService(new AlohaDb()); updaterService = new UpdaterService(new AlohaDb()); }