Ejemplo n.º 1
0
        private void SeedData()
        {
            var context = InMemoryDatabase.GetDbContext();

            context.BuildingTypes.AddRange(TestData);
            context.SaveChanges();
        }
Ejemplo n.º 2
0
        private void SeedData()
        {
            var context = InMemoryDatabase.GetDbContext();

            context.Addresses.AddRange(GetTestData);
            context.SaveChanges();
        }
Ejemplo n.º 3
0
        public async Task GetOrderByStatusWithCorrectStatusShouldReturnTheOrder()
        {
            var context = InMemoryDatabase.GetDbContext();

            await SeedData(context);

            var methodResult = new List <OrderByStatusViewModel>();

            var orderFromDb = GetTestData().FirstOrDefault();

            var expectedResult = Mapper.Map <Order, OrderByStatusViewModel>(orderFromDb,
                                                                            opt => opt.ConfigureMap()
                                                                            .ForMember(dest => dest.IssuerName, m => m.MapFrom(src => src.Issuer.UserName)));

            methodResult.Add(expectedResult);

            var orderStatus = orderFromDb.Status;
            var orderUser   = orderFromDb.Issuer.UserName;

            var orderService = new Mock <IOrderService>();

            orderService.Setup(g => g.GetOrdersByStatus <OrderByStatusViewModel>(orderStatus, orderUser)).Returns(methodResult);

            var actualResult = orderService.Object.GetOrdersByStatus <OrderByStatusViewModel>(orderStatus, orderUser).FirstOrDefault();

            Assert.Same(expectedResult.IssuerName, actualResult.IssuerName);
            Assert.Same(expectedResult.OrderStatus, actualResult.OrderStatus);
        }
Ejemplo n.º 4
0
        public async Task GetAllOrdersSortedByUserThenByCompanyShouldReturnAllOrdersInTheDataBase()
        {
            var context = InMemoryDatabase.GetDbContext();

            await SeedData(context);

            var methodResults = new List <AdminOrderViewModel>();

            var ordersFromDb = GetTestData();

            foreach (var order in ordersFromDb)
            {
                var mappedOrder = Mapper.Map <Order, AdminOrderViewModel>(order,
                                                                          opt => opt.ConfigureMap()
                                                                          .ForMember(dest => dest.IssuerName, m => m.MapFrom(src => src.Issuer.UserName)));
                methodResults.Add(mappedOrder);
            }

            var orderService = new Mock <IOrderService>();

            orderService.Setup(g => g.GetAllOrdersSortedByUserThenByCompany <AdminOrderViewModel>()).Returns(methodResults);

            var actualResults = orderService.Object.GetAllOrdersSortedByUserThenByCompany <AdminOrderViewModel>();

            for (int i = 0; i < methodResults.Count; i++)
            {
                Assert.Same(methodResults[i].IssuerName, actualResults[i].IssuerName);
                Assert.Same(methodResults[i].OrderStatus, actualResults[i].OrderStatus);
            }
        }
Ejemplo n.º 5
0
        public void GetAllOrdersSortedByUserThenByCompanyWithNoOrdersInDataBaseShouldReturnEmpyList()
        {
            var context = InMemoryDatabase.GetDbContext();
            var service = new OrderService(context);

            var actualResult = service.GetAllOrdersSortedByUserThenByCompany <AdminOrderViewModel>();

            Assert.Empty(actualResult);
        }
        public void GetAllInvoiceShouldReturnEmptyListIfThereIsNoIvoices()
        {
            var context = InMemoryDatabase.GetDbContext();
            var service = new InvoiceService(context);

            var invoiceFromDb = service.GetAllInovoices <InvoiceViewModel>();

            Assert.Empty(invoiceFromDb);
        }
Ejemplo n.º 7
0
        public async Task DeleteUnexistingAddressShouldReturnFalse()
        {
            var context   = InMemoryDatabase.GetDbContext();
            var invalidId = 55;

            var addressServices = new AddressServices(context);
            var actualResult    = await addressServices.DeleteAddressAsync(invalidId);

            Assert.IsFalse(actualResult, ShouldReturnFalseMessage);
        }
        public void GetAllInvoiceByUserIdShouldReturnEmptyListIfThereIsNoSuchUser()
        {
            var context = InMemoryDatabase.GetDbContext();
            var service = new InvoiceService(context);

            var fakeId        = "Fake";
            var invoiceFromDb = service.GetAllInovoicesByUserId <InvoiceViewModel>(fakeId);

            Assert.Empty(invoiceFromDb);
        }
Ejemplo n.º 9
0
 public OfferServicesTests()
 {
     this.context                  = InMemoryDatabase.GetDbContext();
     this.mapper                   = this.GetMapper();
     this.imageServices            = new Mock <IImageServices>();
     this.cloudinaryServices       = new Mock <ICloudinaryService>();
     this.userServices             = new Mock <IUserServices>();
     this.realEstateServices       = new Mock <IRealEstateServices>();
     this.referenceNumberGenerator = new Mock <IReferenceNumberGenerator>();
     this.SeedData();
 }
Ejemplo n.º 10
0
        public void GetOrderByStatusWithIncorrectParametersShouldReturnEmptyList()
        {
            var context = InMemoryDatabase.GetDbContext();
            var service = new OrderService(context);

            var missingOrderStatus = OrderStatus.Accepted;
            var missingUserName    = "******";

            var actualResult = service.GetOrdersByStatus <OrderByStatusViewModel>(missingOrderStatus, missingUserName);

            Assert.Empty(actualResult);
        }
Ejemplo n.º 11
0
        public async Task DeleteExistingAddressShouldReturnTrue()
        {
            var context         = InMemoryDatabase.GetDbContext();
            int idToDelete      = 3;
            var addressToDelete = GetTestData.FirstOrDefault(x => x.Id == idToDelete);

            var addressServices = new AddressServices(context);
            var actualResult    = await addressServices.DeleteAddressAsync(idToDelete);

            Assert.IsTrue(actualResult, ShouldReturnFalseMessage);
            Assert.That(addressToDelete.IsDeleted = true);
        }
Ejemplo n.º 12
0
        public async Task CreateOrderAsyncShoulCreateANewOrder()
        {
            var context = InMemoryDatabase.GetDbContext();
            var service = new OrderService(context);

            var clothing = new Clothing();
            var issuerId = "id";

            await service.CreateOrderAsync(clothing, issuerId);

            Assert.NotEmpty(context.Orders);
        }
 public RealEstateServicesTests()
 {
     this.context = InMemoryDatabase.GetDbContext();
     this.SeedData();
     this.realEstateTypeServices = new Mock <IRealEstateTypeServices>();
     this.citiesServices         = new Mock <ICitiesServices>();
     this.neighbourhoodServices  = new Mock <INeighbourhoodServices>();
     this.addressServices        = new Mock <IAddressServices>();
     this.villageServices        = new Mock <IVillageServices>();
     this.buildingTypeServices   = new Mock <IBuildingTypeServices>();
     this.heatingSystemServices  = new Mock <IHeatingSystemServices>();
 }
Ejemplo n.º 14
0
        public async Task GetInvoiceByIdShouldReturnWithMissingIdNull()
        {
            var context = InMemoryDatabase.GetDbContext();

            await SeedData(context);

            var service = new InvoiceService(context);
            var fakeId  = "FakeId";

            var actualResult = service.GetInvoiceById <InvoiceViewModel>(fakeId);

            Assert.Null(actualResult);
        }
Ejemplo n.º 15
0
        public void GetAllInvoiceShuldReturnAllInvoicesInTheDataBase()
        {
            var context = InMemoryDatabase.GetDbContext();
            var service = new InvoiceService(context);

            var expectedResult = GetTestData();
            var actualResult   = service.GetAllInovoices <InvoiceViewModel>().ToList();

            for (int i = 0; i < actualResult.Count(); i++)
            {
                Assert.Equal(expectedResult[i].Id, actualResult[i].Id);
            }
        }
Ejemplo n.º 16
0
        public async Task OnCreateInvoiceAsyncServiceShouldCreateNewInvoice()
        {
            var context = InMemoryDatabase.GetDbContext();
            var service = new InvoiceService(context);

            var userId     = "userId";
            var clothingId = "clothingId";
            var orderId    = "orderId";

            await service.CreateInvoiceAsync(userId, clothingId, orderId);

            var actualResult = await context.Invoices.FirstOrDefaultAsync();

            Assert.NotNull(actualResult);
        }
Ejemplo n.º 17
0
        public async Task GetOrderFromDbByIdShouldReturnTheCorrectOrder()
        {
            var context = InMemoryDatabase.GetDbContext();

            await SeedData(context);

            var mockOrderService = new Mock <IOrderService>();

            var expectedResult = GetTestData().First();

            mockOrderService.Setup(g => g.GetOrderFromDbById(expectedResult.Id)).Returns(expectedResult);

            var service      = mockOrderService.Object;
            var actualResult = service.GetOrderFromDbById(expectedResult.Id);

            Assert.Same(expectedResult, actualResult);
        }
Ejemplo n.º 18
0
        public async Task GetOrderByIdWihtNonExistantIdShouldReturnNull()
        {
            var context = InMemoryDatabase.GetDbContext();

            await SeedData(context);

            var orderService = new Mock <IOrderService>();

            var fakeId            = "nonexistent";
            var methodReturnValue = new OrderByStatusViewModel();

            orderService.Setup(g => g.GetOrderById <OrderByStatusViewModel>("Id")).Returns(methodReturnValue);

            var service      = orderService.Object;
            var actualResult = service.GetOrderById <OrderByStatusViewModel>(fakeId);

            Assert.Null(actualResult);
        }
Ejemplo n.º 19
0
        public async Task GetOrderFromDbByIdWhitNoneexistenceIdShouldReturnNull()
        {
            var context = InMemoryDatabase.GetDbContext();

            await SeedData(context);

            var orderService = new Mock <IOrderService>();

            var fakeId = "nonexistent";
            var order  = new Order();

            orderService.Setup(g => g.GetOrderFromDbById("Id")).Returns(order);

            var service      = orderService.Object;
            var actualResult = service.GetOrderFromDbById(fakeId);

            Assert.Null(actualResult);
        }
Ejemplo n.º 20
0
        public async Task GetOrderByIdShouldReturnTheCorrectOrder()
        {
            var context = InMemoryDatabase.GetDbContext();

            await SeedData(context);

            var mockOrderService = new Mock <IOrderService>();

            var methodReturnValue = new OrderByStatusViewModel();
            var expectedResult    = GetTestData().First();

            mockOrderService.Setup(g => g.GetOrderById <OrderByStatusViewModel>(expectedResult.Id)).Returns(methodReturnValue);

            var service       = mockOrderService.Object;
            var returnedOrder = service.GetOrderById <OrderByStatusViewModel>(expectedResult.Id);

            Assert.Same(expectedResult.Clothing.Name, returnedOrder.ClothingName);
        }
Ejemplo n.º 21
0
        public async Task EditOrderStatusWithWrongStatusShouldNotChangeTheOrderStatus()
        {
            var context = InMemoryDatabase.GetDbContext();

            await SeedData(context);

            var orderService = new OrderService(context);

            var orderToEdit      = context.Orders.FirstOrDefault();
            var statusToChangeTo = "FakeStatus";
            var orderId          = orderToEdit.Id;

            await orderService.EditOrderStatusAsync(orderId, statusToChangeTo);

            var expectedResult = OrderStatus.Rejected;
            var actualResult   = orderToEdit.Status;

            Assert.NotEqual(expectedResult, actualResult);
        }
        public async Task OnCreateClothingAsyncServiceShouldCreateNewClothing()
        {
            IFormFile file     = null;
            string    filename = "SomeName";

            Mock <ICloudinaryService> cloudinaryServiceMoq = new Mock <ICloudinaryService>();
            var filemoq = cloudinaryServiceMoq.Setup(x => x.UploadDiagramImage(file, filename)).Returns(Task.Run(() => filename));

            var context = InMemoryDatabase.GetDbContext();

            string   name      = "Jacket";
            string   fabric    = "Textile";
            FormFile fileForDb = null;

            using (var stream = File.OpenRead("D:\\Ivteks72.App\\Ivteks72WebApp\\Ivteks72.App\\wwwroot\\lib\\pictures\\Location.png"))
            {
                fileForDb = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name))
                {
                    Headers     = new HeaderDictionary(),
                    ContentType = "application/pdf"
                };
            }

            int     quantity     = 1;
            decimal pricePerUnit = 2.20m;

            var service = new ClothingService(context, cloudinaryServiceMoq.Object);

            var testClothing = new Clothing
            {
                ClothingDiagramURL = null,
                Fabric             = fabric,
                Name         = name,
                PricePerUnit = pricePerUnit,
                Quantity     = quantity,
            };

            var actualclothing = await service.CreateClothingAsync(name, fabric, fileForDb, quantity, pricePerUnit);

            Assert.NotNull(actualclothing);
            Assert.IsAssignableFrom(testClothing.GetType(), actualclothing);
        }
Ejemplo n.º 23
0
        public async Task GetInvoiceByIdShouldReturnWithCorrectIdTheInvoice()
        {
            var context = InMemoryDatabase.GetDbContext();

            await SeedData(context);

            var orderFromDb = GetTestData().FirstOrDefault();

            var expectedResult = Mapper.Map <Invoice, InvoiceViewModel>(orderFromDb);

            var id = expectedResult.Id;

            var InvoiceService = new Mock <IInvoiceService>();

            InvoiceService.Setup(g => g.GetInvoiceById <InvoiceViewModel>(id)).Returns(expectedResult);

            var actualResult = InvoiceService.Object.GetInvoiceById <InvoiceViewModel>(id);

            Assert.Equal(expectedResult.Id, actualResult.Id);
        }
 public ReferenceNumbersGeneratorTests()
 {
     this.context = InMemoryDatabase.GetDbContext();
     this.SeedData();
 }
 public ImageServicesTests()
 {
     this.context = InMemoryDatabase.GetDbContext();
     //this.SeedData();
 }
Ejemplo n.º 26
0
 public HeatingSystemServicesTests()
 {
     context = InMemoryDatabase.GetDbContext();
     this.SeedData();
 }
Ejemplo n.º 27
0
 public UsersServicesTests()
 {
     this.context = InMemoryDatabase.GetDbContext();
 }
Ejemplo n.º 28
0
 public BuildingTypeServicesTests()
 {
     this.context = InMemoryDatabase.GetDbContext();
     this.SeedData();
 }
 public VisitorsSessionServicesTests()
 {
     this.context = InMemoryDatabase.GetDbContext();
     this.SeedData();
 }
Ejemplo n.º 30
0
 public CitiesServicesTests()
 {
     this.context = InMemoryDatabase.GetDbContext();
     this.SeedData();
 }