Esempio n. 1
0
        public List <ActivityDTO> GetPosibleActivities()
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap <Activity, ActivityDTO>()
                                                 .ForMember("GetPosibleRooms", opt => opt.Ignore()));
            var mapper = new Mapper(config);

            return(mapper.Map <List <ActivityDTO> >(DI_Resolver.GetDIResolver().Get <IUnitOfWork <AntiCafeDb> >().roomsRepository.FindById(Id).PosibleActivities.ToList()));
        }
Esempio n. 2
0
        public List <EquipmentDTO> GetRoomEquipment()
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap <Equipment, EquipmentDTO>()
                                                 .ForMember("GetRoomsThatHaveIt", opt => opt.Ignore()));
            var mapper = new Mapper(config);

            return(mapper.Map <List <EquipmentDTO> >(DI_Resolver.GetDIResolver().Get <IUnitOfWork <AntiCafeDb> >().roomsRepository.FindById(Id).RoomEquipment.ToList()));
        }
Esempio n. 3
0
        public List <OrderDTO> GetRoomOrders()
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap <Order, OrderDTO>()
                                                 .ForMember("GetOrderedRooms", opt => opt.Ignore()));
            var mapper = new Mapper(config);

            return(mapper.Map <List <OrderDTO> >(DI_Resolver.GetDIResolver().Get <IUnitOfWork <AntiCafeDb> >().roomsRepository.FindById(Id).RoomOrders.ToList()));
        }
Esempio n. 4
0
        public void GetAllActivitiesTest()
        {
            //Arrange
            List <Activity> activities = new List <Activity>()
            {
                new Activity()
                {
                    Id = 1, Name = "FirstActivity", Description = "FirstDescription", IsSpecialActivity = false, PricePerHour = 100
                },
                new Activity()
                {
                    Id = 2, Name = "SecondActivity", Description = "SecondDescription", IsSpecialActivity = false, PricePerHour = 200
                },
                new Activity()
                {
                    Id = 3, Name = "ThirdActivity", Description = "ThirdDescription", IsSpecialActivity = true, PricePerHour = 100
                },
                new Activity()
                {
                    Id = 4, Name = "ForthActivity", Description = "ForthDescription", IsSpecialActivity = false, PricePerHour = 300
                },
                new Activity()
                {
                    Id = 5, Name = "FifthActivity", Description = "FifthDescription", IsSpecialActivity = true, PricePerHour = 100
                },
                new Activity()
                {
                    Id = 6, Name = "SixthActivity", Description = "SixthDescription", IsSpecialActivity = false, PricePerHour = 500
                },
            };

            var mapper = DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>().ActivityToDTOMapper();

            //Act
            var activityRepositoryMock = new Mock <IGenericRepository <Activity> >();

            activityRepositoryMock.Setup(a => a.Get(It.IsAny <Func <Activity, bool> >())).Returns(activities.Where(q => q.IsSpecialActivity == false).ToList());

            var IUnitOfWorkMock = new Mock <IUnitOfWork <AntiCafeDb> >();

            IUnitOfWorkMock.Setup(u => u.activitiesRepository).Returns(activityRepositoryMock.Object);

            IActivityService   activityService = new ActivityService(IUnitOfWorkMock.Object, DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>());
            List <ActivityDTO> activityDTOs    = activityService.GetAllActivities();

            //Assert
            activities = activities.Where(a => a.IsSpecialActivity == false).ToList();
            Assert.AreNotEqual(activityDTOs.Count, 0);
            for (int i = 0; i < activityDTOs.Count; i++)
            {
                Assert.AreEqual(activityDTOs[i].Id, activities[i].Id);
                Assert.AreEqual(activityDTOs[i].Name, activities[i].Name);
                Assert.AreEqual(activityDTOs[i].Description, activities[i].Description);
                Assert.AreEqual(activityDTOs[i].PricePerHour, activities[i].PricePerHour);
                Assert.AreEqual(activityDTOs[i].IsSpecialActivity, activities[i].IsSpecialActivity);
            }
        }
        public List <RoomDTO> GetRoomsThatHaveIt()
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap <Room, RoomDTO>()
                                                 .ForMember("GetRoomOrders", opt => opt.Ignore())
                                                 .ForMember("GetPosibleActivities", opt => opt.Ignore())
                                                 .ForMember("GetRoomEquipment", opt => opt.Ignore()));
            var mapper = new Mapper(config);

            return(mapper.Map <List <RoomDTO> >(DI_Resolver.GetDIResolver().Get <IUnitOfWork <AntiCafeDb> >().equipmentRepository.FindById(Id).RoomsThatHaveIt.ToList()));
        }
Esempio n. 6
0
        public void CreateNewActivityTest()
        {
            //Arrange
            ActivityDTO newActivity = new ActivityDTO()
            {
                Id = 1, Name = "NewActivity", IsSpecialActivity = false, PricePerHour = 100
            };
            List <RoomDTO> roomsToAdd = new List <RoomDTO>()
            {
                new RoomDTO()
                {
                    Id = 2, Name = "Room2"
                },
            };

            List <Room> roomsOriginal = new List <Room>()
            {
                new Room()
                {
                    Id = 2, Name = "Room2"
                },
            };

            var      mapper    = DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>().DTOToActivityMapper();
            Activity activity1 = mapper.Map <Activity>(newActivity);
            int      id        = 2;

            //Act
            var activityRepositoryMock = new Mock <IGenericRepository <Activity> >();

            activityRepositoryMock.Setup(a => a.Create(activity1));

            var roomRepositoryMock = new Mock <IGenericRepository <Room> >();

            roomRepositoryMock.Setup(r => r.FindById(id)).Returns(roomsOriginal.Where(r => r.Id == id).FirstOrDefault());

            var IUnitOfWorkMock = new Mock <IUnitOfWork <AntiCafeDb> >();

            IUnitOfWorkMock.Setup(u => u.activitiesRepository).Returns(activityRepositoryMock.Object);
            IUnitOfWorkMock.Setup(u => u.roomsRepository).Returns(roomRepositoryMock.Object);

            IActivityService activityService = new ActivityService(IUnitOfWorkMock.Object, DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>());
            ActivityDTO      createdActivity = activityService.CreateNewActivity(newActivity, roomsToAdd);

            //Assert
            Assert.AreEqual(createdActivity.Id, newActivity.Id);
            Assert.AreEqual(createdActivity.Name, newActivity.Name);
            Assert.AreEqual(createdActivity.IsSpecialActivity, newActivity.IsSpecialActivity);
            Assert.AreEqual(createdActivity.PricePerHour, newActivity.PricePerHour);
        }
Esempio n. 7
0
        public void CreateNewOrderTest()
        {
            //Arrange
            List <Order>   orders        = new List <Order>();
            List <RoomDTO> roomDTOsToAdd = new List <RoomDTO>()
            {
                new RoomDTO()
                {
                    Id = 1, Name = "Room1"
                },
                new RoomDTO()
                {
                    Id = 2, Name = "Room2"
                },
                new RoomDTO()
                {
                    Id = 3, Name = "Room3"
                }
            };

            //Act
            OrderDTO testOrderDTO = new OrderDTO()
            {
                Id = 1, Name = "Customer1", Surname = "Surname1", StartDate = new DateTime(2020, 4, 5), Hours = 1
            };
            var   mapper    = DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>().DTOToOrderMapper();
            Order testOrder = mapper.Map <Order>(testOrderDTO);

            List <Room> roomsToAdd = new List <Room>();

            mapper = DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>().DTOToRoomMapper();
            for (int i = 0; i < roomDTOsToAdd.Count; i++)
            {
                roomsToAdd.Add(mapper.Map <Room>(roomDTOsToAdd[i]));
            }

            testOrder.OrderedRooms = roomsToAdd;

            var mock = new Mock <IGenericRepository <Order> >();

            mock.Setup(o => o.Create(testOrder)).Callback(() => { orders.Add(testOrder); });
            mock.Object.Create(testOrder);

            //Assert
            Assert.AreEqual(orders.Count, 1);
            for (int i = 0; i < testOrder.OrderedRooms.Count; i++)
            {
                Assert.AreEqual(testOrder.OrderedRooms.ToList()[i].Id, roomDTOsToAdd[i].Id);
            }
        }
Esempio n. 8
0
        public void DTOToRoomMapper()
        {
            //Arange
            IMappingConfigsGenerator generator = DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>();
            Mapper DTOToRoomMapper             = generator.DTOToRoomMapper();

            //Act
            RoomDTO roomDTO = new RoomDTO()
            {
                Id = 1, Name = "Room1"
            };
            Room room = DTOToRoomMapper.Map <Room>(roomDTO);

            //Assert
            Assert.AreEqual(roomDTO.Id, room.Id);
            Assert.AreEqual(roomDTO.Name, room.Name);
        }
Esempio n. 9
0
        public void RoomToDTOMapperTest()
        {
            //Arrange
            IMappingConfigsGenerator generator = DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>();
            Mapper RoomTODTOMapper             = generator.RoomToDTOMapper();

            //Act
            Room room = new Room()
            {
                Id = 1, Name = "Room1"
            };
            RoomDTO roomDTO = RoomTODTOMapper.Map <RoomDTO>(room);

            //Assert
            Assert.AreEqual(room.Id, roomDTO.Id);
            Assert.AreEqual(room.Name, roomDTO.Name);
        }
Esempio n. 10
0
        public void GetAllRoomsTest()
        {
            //Arrange
            List <Room> rooms = new List <Room>()
            {
                new Room()
                {
                    Id = 1, Name = "Room1"
                },
                new Room()
                {
                    Id = 2, Name = "Room2"
                },
                new Room()
                {
                    Id = 3, Name = "Room3"
                },
                new Room()
                {
                    Id = 4, Name = "Room4"
                }
            };
            Mapper mapper = DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>().RoomToDTOMapper();

            //Act
            var RoomRepositoryMock = new Mock <IGenericRepository <Room> >();

            RoomRepositoryMock.Setup(m => m.Get()).Returns(rooms);

            var IUnitOfWorkMock = new Mock <IUnitOfWork <AntiCafeDb> >();

            IUnitOfWorkMock.Setup(i => i.roomsRepository).Returns(RoomRepositoryMock.Object);

            IRoomService   roomService = new RoomService(IUnitOfWorkMock.Object, DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>());
            List <RoomDTO> mappedRooms = roomService.GetAllRooms();

            //Assert
            for (int i = 0; i < mappedRooms.Count; i++)
            {
                Assert.AreEqual(mappedRooms[i].Id, rooms[i].Id);
                Assert.AreEqual(mappedRooms[i].Name, rooms[i].Name);
            }

            Assert.AreEqual(mappedRooms.Count, rooms.Count);
        }
Esempio n. 11
0
        public void DTOToActivityMapper()
        {
            //Arange
            IMappingConfigsGenerator generator = DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>();
            Mapper DTOToActivityMapper         = generator.DTOToActivityMapper();

            //Act
            ActivityDTO activityDTO = new ActivityDTO()
            {
                Id = 1, Name = "SomeName", Description = "SomeDescription", IsSpecialActivity = true, PricePerHour = 100
            };
            Activity activity = DTOToActivityMapper.Map <Activity>(activityDTO);

            //Assert
            Assert.AreEqual(activityDTO.Id, activity.Id);
            Assert.AreEqual(activityDTO.Name, activity.Name);
            Assert.AreEqual(activityDTO.IsSpecialActivity, activity.IsSpecialActivity);
            Assert.AreEqual(activityDTO.PricePerHour, activity.PricePerHour);
            Assert.AreEqual(activityDTO.Description, activity.Description);
        }
Esempio n. 12
0
        public void DTOToOrderMapper()
        {
            //Arange
            IMappingConfigsGenerator generator = DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>();
            Mapper DTOToOrderMapper            = generator.DTOToOrderMapper();

            //Act
            DateTime dateTime = DateTime.Now;
            OrderDTO orderDTO = new OrderDTO()
            {
                Id = 1, Hours = 2, Name = "SomeName", Surname = "SomeSurname", StartDate = dateTime
            };
            Order order = DTOToOrderMapper.Map <Order>(orderDTO);

            //Assert
            Assert.AreEqual(orderDTO.Id, order.Id);
            Assert.AreEqual(orderDTO.Name, order.Name);
            Assert.AreEqual(orderDTO.Hours, order.Hours);
            Assert.AreEqual(orderDTO.Surname, order.Surname);
            Assert.AreEqual(orderDTO.StartDate, order.StartDate);
        }
Esempio n. 13
0
        public void GetRoomTest()
        {
            //Arrange
            List <Room> rooms = new List <Room>()
            {
                new Room()
                {
                    Id = 1, Name = "Room1"
                },
                new Room()
                {
                    Id = 2, Name = "Room2"
                },
                new Room()
                {
                    Id = 3, Name = "Room3"
                }
            };
            int    id     = 2;
            Room   room   = rooms.Where(r => r.Id == id).FirstOrDefault();
            Mapper mapper = DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>().RoomToDTOMapper();

            //Act
            var RoomRepositoryMock = new Mock <IGenericRepository <Room> >();

            RoomRepositoryMock.Setup(m => m.FindById(id)).Returns(rooms.Where(t => t.Id == id).FirstOrDefault());

            var IUnitOfWorkMock = new Mock <IUnitOfWork <AntiCafeDb> >();

            IUnitOfWorkMock.Setup(i => i.roomsRepository).Returns(RoomRepositoryMock.Object);

            IRoomService roomService = new RoomService(IUnitOfWorkMock.Object, DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>());
            RoomDTO      roomDTO     = roomService.GetRoom(id);

            //Assert
            Assert.AreEqual(roomDTO.Id, room.Id);
            Assert.AreEqual(roomDTO.Name, room.Name);
        }
 public ActivitiesBLRepository()
 {
     unitOfWork     = DI_Resolver.GetDIResolver().Get <IUnitOfWork <AntiCafeDb> >();
     mappingConfigs = DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>();
 }
Esempio n. 15
0
        public void GetActiveOrdersTest()
        {
            //Arrange
            Room room1 = new Room()
            {
                Id = 1, Name = "Room1"
            };
            Room room2 = new Room()
            {
                Id = 2, Name = "Room2"
            };
            Room room3 = new Room()
            {
                Id = 3, Name = "Room3"
            };
            Room room4 = new Room()
            {
                Id = 4, Name = "Room4"
            };
            Room room5 = new Room()
            {
                Id = 5, Name = "Room5"
            };

            List <Order> someOrders = new List <Order>()
            {
                new Order()
                {
                    Id = 1, Name = "Customer1", Surname = "Surname1", StartDate = new DateTime(2020, 4, 3), Hours = 1, OrderedRooms = new List <Room>()
                    {
                        room1, room2
                    }
                },
                new Order()
                {
                    Id = 2, Name = "Customer2", Surname = "Surname2", StartDate = new DateTime(2020, 4, 6), Hours = 2, OrderedRooms = new List <Room>()
                    {
                        room2, room3
                    }
                },
                new Order()
                {
                    Id = 3, Name = "Customer3", Surname = "Surname3", StartDate = new DateTime(2020, 4, 5), Hours = 2, OrderedRooms = new List <Room>()
                    {
                        room1, room5
                    }
                },
                new Order()
                {
                    Id = 4, Name = "Customer4", Surname = "Surname4", StartDate = new DateTime(2020, 4, 3), Hours = 2, OrderedRooms = new List <Room>()
                    {
                        room4
                    }
                },
                new Order()
                {
                    Id = 5, Name = "Customer5", Surname = "Surname5", StartDate = new DateTime(2020, 4, 5), Hours = 2, OrderedRooms = new List <Room>()
                    {
                        room4, room5
                    }
                }
            };

            DateTime someDateTime = new DateTime(2020, 4, 5);
            Room     searchedRoom = room5;

            var mock = new Mock <IGenericRepository <Order> >();

            mock.Setup(o => o.Get()).Returns(someOrders.Where(o => o.StartDate.Date == someDateTime.Date));


            //Act
            var             mapper    = DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>().OrderToDTOMapper();
            List <OrderDTO> AllOrders = mapper.Map <List <OrderDTO> >(mock.Object.Get());

            for (int i = 0; i < AllOrders.Count; i++)
            {
                var            roomMapper   = DI_Resolver.GetDIResolver().Get <IMappingConfigsGenerator>().RoomToDTOMapper();
                List <RoomDTO> orderedRooms = roomMapper.Map <List <RoomDTO> >(someOrders.Where(o => o.Id == AllOrders[i].Id).FirstOrDefault().OrderedRooms);

                for (int j = 0; j < orderedRooms.Count; j++)
                {
                    if (orderedRooms[j].Id == searchedRoom.Id)
                    {
                        break;
                    }
                    else
                    {
                        if (j == orderedRooms.Count - 1)
                        {
                            AllOrders.RemoveAt(i);
                            i = i - 1;
                            if (i < 0)
                            {
                                i = 0;
                            }
                        }
                    }
                }
            }


            //Assert
            for (int i = 0; i < AllOrders.Count; i++)
            {
                Assert.AreEqual(someDateTime, AllOrders[i].StartDate);
                Assert.IsTrue(someOrders.Where(o => o.Id == AllOrders[i].Id).FirstOrDefault().OrderedRooms.Contains(searchedRoom));
            }
        }