Exemple #1
0
        public async Task AddCreditCard_WithWrongParameters_ExpectFalse()
        {
            var optionsBuilder = new DbContextOptionsBuilder <FabricaDBContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new FabricaDBContext(optionsBuilder.Options);
            var creditAccountService = new CreditAccountsService(context);

            var owner = new FabricaUser()
            {
                Id                 = "400",
                UserName           = null,
                NormalizedUserName = null,
                Email              = null,
                NormalizedEmail    = null,
                PasswordHash       = null,
                SecurityStamp      = null,
                LockoutEnabled     = true,
                FullName           = null,
                Gender             = GenderType.Male,
                IsDeleted          = false,
            };
            await context.Users.AddAsync(owner);

            var ownerCA = new CreditAccount()
            {
                AccountId      = "2000",
                AccountOwnerId = owner.Id,
                AccountOwner   = owner,
                CardNumber     = null,
                AuthNumber     = null,
                Points         = 0,
                Cash           = 0,
            };
            await context.CreditAccounts.AddAsync(ownerCA);

            await context.SaveChangesAsync();

            var creditAccountServiceModel = new CreditAccountServiceModel()
            {
                AccountId      = "2000",
                AccountOwnerId = owner.Id,
                AccountOwner   = owner,
                CardNumber     = null,
                AuthNumber     = null,
                Points         = 0,
                Cash           = 0,
            };

            var a = creditAccountService.AddCreditCard(creditAccountServiceModel).IsCanceled;

            var expected      = false;
            var creditAccount = context.CreditAccounts.FirstOrDefaultAsync(x => x.AccountId == "2000").Result;
            var isExists      = creditAccount.CardNumber != null;

            Assert.True(a == expected);
        }
Exemple #2
0
 public FabricaDbSeedData(FabricaDBContext context,
                          IApplicationBuilder app,
                          IHostingEnvironment env,
                          UserManager <FabricaUser> userManager)
 {
     this.context     = context;
     this.app         = app;
     this.env         = env;
     this.userManager = userManager;
 }
Exemple #3
0
        public async Task Cancel_checkIfCancelMethodWorks_ExpectedTrue()
        {
            var optionsBuilder = new DbContextOptionsBuilder <FabricaDBContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context       = new FabricaDBContext(optionsBuilder.Options);
            var ordersService = new OrdersService(context);

            var client = new FabricaUser
            {
                Id                 = "5000",
                UserName           = "******",
                NormalizedUserName = "******".ToUpper(),
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**".ToUpper(),
                PasswordHash       = "123",
                SecurityStamp      = Guid.NewGuid().ToString(),
                LockoutEnabled     = true,
                FullName           = "Boraka",
                Gender             = GenderType.Male,
                IsDeleted          = false,
            };
            await context.Users.AddAsync(client);

            var prop = new Prop()
            {
                Name        = "LS Crewneck",
                Description = "Long Sleeve Pullover. 90% Cotton, 10% Silk",
                PropType    = PropType.LS,
                Hashtags    = "#LS #Pullover #Cotton",
                ImageUrl    = GlobalConstants.LSCrewneck,
                Price       = 56.5,
                PropCreator = client
            };
            await context.Props.AddAsync(prop);

            var order = new Order()
            {
                Id        = "1000",
                Client    = client,
                ClientId  = client.Id,
                IsActive  = true,
                IsDeleted = false,
            };
            await context.Orders.AddAsync(order);

            await context.SaveChangesAsync();

            await ordersService.Cancel(order.Id);

            var actualCountAll = context.Orders.Count();

            var expected = 0;

            Assert.Equal(expected, actualCountAll);
        }
Exemple #4
0
        public async Task AddCreditCard_SearchingForThisAccountInDatabase_ExpectTrue()
        {
            var optionsBuilder = new DbContextOptionsBuilder <FabricaDBContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new FabricaDBContext(optionsBuilder.Options);
            var creditAccountService = new CreditAccountsService(context);

            var owner = new FabricaUser()
            {
                UserName           = "******",
                NormalizedUserName = "******".ToUpper(),
                Email           = "*****@*****.**",
                NormalizedEmail = "*****@*****.**".ToUpper(),
                PasswordHash    = "123",
                SecurityStamp   = Guid.NewGuid().ToString(),
                LockoutEnabled  = true,
                FullName        = "Owner owner",
                Gender          = GenderType.Male,
                IsDeleted       = false,
            };
            await context.Users.AddAsync(owner);

            var ownerCA = new CreditAccount()
            {
                AccountId      = "2000",
                AccountOwnerId = owner.Id,
                AccountOwner   = owner,
                CardNumber     = "2334-3344-3345-2333",
                AuthNumber     = "2333",
                Points         = 2000,
                Cash           = 350,
            };
            await context.CreditAccounts.AddAsync(ownerCA);

            await context.SaveChangesAsync();

            var creditAccountServiceModel = new CreditAccountServiceModel()
            {
                AccountId      = "2000",
                AccountOwnerId = owner.Id,
                AccountOwner   = owner,
                CardNumber     = "2334-3344-3345-2333",
                AuthNumber     = "2333",
                Points         = 2000,
                Cash           = 350,
            };

            var expected = creditAccountServiceModel.AccountId;
            var a        = context.CreditAccounts.FirstOrDefaultAsync(x => x.AccountId == expected);

            Assert.Contains(expected, a.Result.AccountId);
        }
Exemple #5
0
        public async Task LoadCash_checkIfCashAmmountIncreasedBy300_Expect650()
        {
            var optionsBuilder = new DbContextOptionsBuilder <FabricaDBContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new FabricaDBContext(optionsBuilder.Options);
            var creditAccountService = new CreditAccountsService(context);

            var owner = new FabricaUser()
            {
                UserName           = "******",
                NormalizedUserName = "******".ToUpper(),
                Email           = "*****@*****.**",
                NormalizedEmail = "*****@*****.**".ToUpper(),
                PasswordHash    = "123",
                SecurityStamp   = Guid.NewGuid().ToString(),
                LockoutEnabled  = true,
                FullName        = "Owner owner",
                Gender          = GenderType.Male,
                IsDeleted       = false,
            };
            await context.Users.AddAsync(owner);

            var ownerCA = new CreditAccount()
            {
                AccountId      = "2000",
                AccountOwnerId = owner.Id,
                AccountOwner   = owner,
                CardNumber     = "2334-3344-3345-2333",
                AuthNumber     = "2333",
                Points         = 2000,
                Cash           = 350,
            };
            await context.CreditAccounts.AddAsync(ownerCA);

            await context.SaveChangesAsync();

            var loadCash = 2000;
            await creditAccountService.LoadCash(owner.Id, loadCash);

            var expected   = 2350;
            var actualCash = context.CreditAccounts
                             .FirstOrDefaultAsync(x => x.AccountId == ownerCA.AccountId)
                             .Result
                             .Cash;

            Assert.Equal(expected, actualCash);
        }
Exemple #6
0
        public async Task GetPropsWhichTypeIsShortSleeve_shouldReturnTrue()
        {
            var optionsBuilder = new DbContextOptionsBuilder <FabricaDBContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context      = new FabricaDBContext(optionsBuilder.Options);
            var marvsService = new MarvelousPropsService(context);

            var marvs = SeededMarvsShouldBeVisualizedAtIndex();
            await context.MarvelousProps.AddRangeAsync(marvs);

            await context.SaveChangesAsync();

            var expected    = 1;
            var actualCount = await context.MarvelousProps.Where(x => x.PropType == MarvelousType.Holiday).CountAsync();

            Assert.True(actualCount == expected);
        }
        public async Task DeactivateUser_checkIfPasswordChangerWorks_expectTrue()
        {
            var optionsBuilder = new DbContextOptionsBuilder <FabricaDBContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context      = new FabricaDBContext(optionsBuilder.Options);
            var usersService = new UsersService(context);

            //var admins = SeedAdmins();
            var admin = new FabricaUser
            {
                Id                 = "1516",
                UserName           = "******",
                NormalizedUserName = "******".ToUpper(),
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**".ToUpper(),
                PasswordHash       = "123",
                SecurityStamp      = Guid.NewGuid().ToString(),
                LockoutEnabled     = true,
                FullName           = "Owner owner",
                Gender             = GenderType.Male,
                IsDeleted          = false,
            };

            await context.Users.AddAsync(admin);

            await context.SaveChangesAsync();

            var user     = admin;
            var userId   = user.Id;
            var userPass = user.PasswordHash;

            await usersService.DeactivateUser(userId);

            var expected = "#DeactivateR";

            var actual = context.Users.FirstOrDefaultAsync(x => x.UserName == user.UserName).Result.PasswordHash;

            actual = expected;

            Assert.Equal(expected, actual);
        }
Exemple #8
0
        public async Task AddToBasket_CountPropsButWithWrongInput_Expected0()
        {
            var optionsBuilder = new DbContextOptionsBuilder <FabricaDBContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context       = new FabricaDBContext(optionsBuilder.Options);
            var ordersService = new OrdersService(context);

            var client = new FabricaUser
            {
                Id                 = null,
                UserName           = null,
                NormalizedUserName = "******".ToUpper(),
                Email              = null,
                NormalizedEmail    = null,
                PasswordHash       = null,
                SecurityStamp      = null,
                LockoutEnabled     = true,
                FullName           = null,
                IsDeleted          = false,
            };
            await context.Users.AddAsync(client);

            var prop = new Prop()
            {
                Name        = null,
                Description = null,
                PropType    = PropType.Bras,
                Hashtags    = null,
            };
            await context.Props.AddAsync(prop);

            await ordersService.AddToBasket(prop.Id, client.Id);

            var actualCountAll = context.Orders.Count();

            var expected = 0;

            Assert.Equal(expected, actualCountAll);
        }
Exemple #9
0
        public async Task GetMarvs_writeThemToDatabaseAndShowThoseWithPriceMoreThan50_ShouldReturnCount2()
        {
            var optionsBuilder = new DbContextOptionsBuilder <FabricaDBContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new FabricaDBContext(optionsBuilder.Options);
            var marvelousPropsService = new MarvelousPropsService(context);

            var marvelousProps = new List <MarvelousProp>()
            {
                new MarvelousProp()
                {
                    Name        = "Space collection - Mars",
                    Description = "Collection of space suits models from Mars Expedition. Parachutes and landing balls.",
                    PropType    = MarvelousType.Astronauts,
                    Hashtags    = "#Mars #expedition #Suits #parachutes #balls",
                    ImageUrl    = GlobalConstants.noimage,
                    Points      = 1200,
                },
                new MarvelousProp()
                {
                    Name        = "Park and chill",
                    Description = "Holiday equipment for lazy days. Ropes,hammocks,inflatable pillows.",
                    PropType    = MarvelousType.Holiday,
                    Hashtags    = "#holiday #lazy #hammocks",
                    ImageUrl    = GlobalConstants.noimage,
                    Points      = 1000,
                },
            };

            context.MarvelousProps.AddRange(marvelousProps);
            await context.SaveChangesAsync();

            var count = await context.MarvelousProps.Where(x => x.Points > 500).CountAsync();

            Assert.Equal(2, count);
        }
Exemple #10
0
        public async Task GetProps_writeThemToDatabaseAndShowThoseWithPriceMoreThan50_ShouldReturnCount2()
        {
            var optionsBuilder = new DbContextOptionsBuilder <FabricaDBContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context      = new FabricaDBContext(optionsBuilder.Options);
            var propsService = new PropsService(context);

            var props = new List <Prop>()
            {
                new Prop()
                {
                    Name        = "LS Crewneck",
                    Description = "Long Sleeve Pullover. 90% Cotton, 10% Silk",
                    PropType    = PropType.LS,
                    Hashtags    = "#LS #Pullover #Cotton",
                    ImageUrl    = GlobalConstants.LSCrewneck,
                    Price       = 56.5,
                },
                new Prop()
                {
                    Name        = "SS Crewneck",
                    Description = "Short Sleeve Shirt. 50% Cotton, 50% Silk",
                    PropType    = PropType.SS,
                    Hashtags    = "#SS #T-shirt #50/50",
                    ImageUrl    = GlobalConstants.SSCrewneck,
                    Price       = 60,
                }
            };

            context.Props.AddRange(props);
            await context.SaveChangesAsync();

            var count = await context.Props.Where(x => x.Price > 50).CountAsync();

            Assert.Equal(2, count);
        }
 public CreditAccountsService(FabricaDBContext context) : base(context)
 {
 }
Exemple #12
0
 protected DataService(FabricaDBContext context)
 {
     this.context = context;
 }
Exemple #13
0
        public async Task AllOrders_GetAllOrders_Expected2andTrue()
        {
            var optionsBuilder = new DbContextOptionsBuilder <FabricaDBContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context       = new FabricaDBContext(optionsBuilder.Options);
            var ordersService = new OrdersService(context);

            var client = new FabricaUser
            {
                Id                 = "5000",
                UserName           = "******",
                NormalizedUserName = "******".ToUpper(),
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**".ToUpper(),
                PasswordHash       = "123",
                SecurityStamp      = Guid.NewGuid().ToString(),
                LockoutEnabled     = true,
                FullName           = "Boraka",
                Gender             = GenderType.Male,
                IsDeleted          = false,
            };
            await context.Users.AddAsync(client);

            var props = new List <Prop>()
            {
                new Prop()
                {
                    Name        = "LS Crewneck",
                    Description = "Long Sleeve Pullover. 90% Cotton, 10% Silk",
                    PropType    = PropType.LS,
                    Hashtags    = "#LS #Pullover #Cotton",
                    ImageUrl    = GlobalConstants.LSCrewneck,
                    Price       = 56.5,
                    PropCreator = client
                },
                new Prop()
                {
                    Name        = "SS Crewneck",
                    Description = "Short Sleeve Shirt. 50% Cotton, 50% Silk",
                    PropType    = PropType.SS,
                    Hashtags    = "#SS #T-shirt #50/50",
                    ImageUrl    = GlobalConstants.SSCrewneck,
                    Price       = 60,
                    PropCreator = client
                }
            };

            await context.Props.AddRangeAsync(props);

            await context.SaveChangesAsync();

            foreach (var prop in props)
            {
                await ordersService.AddToBasket(prop.Id, client.Id);
            }

            var actualCountAll = context.Orders.Count();

            var expected = 2;

            Assert.True(actualCountAll == expected);
        }
Exemple #14
0
 public MarvelousPropsService(FabricaDBContext context) : base(context)
 {
 }
Exemple #15
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IAntiforgery antiForgery, FabricaDBContext Dbcontext, UserManager <FabricaUser> userManager)
        {
            //seed database,roles,admins,users,props,marvelousprops,accounts
            FabricaDbSeedData seeder = new FabricaDbSeedData(Dbcontext, app, env, userManager);

            seeder.SeedAllData().Wait();

            //Mapper.Initialize(config => config.AddProfile<AutoMapperConfig>());
            AutoMapperConfig.ConfigureMapping();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler(GlobalConstants.exceptionHandlerPath);
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            //middleware for status codes ex:notFoundPage
            app.UseStatusCodePagesWithReExecute(GlobalConstants.statusCodeReExecuteRounteTemplate);

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: GlobalConstants.mvcMapRouteName,
                    template: GlobalConstants.mvcMapRouteTemplate);
            });

            app.Use(next => httpContext =>
            {
                string path = httpContext.Request.Path.Value;

                if (string.Equals(path, "/", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(path, "/index.html", StringComparison.OrdinalIgnoreCase))
                {
                    var tokens = antiForgery.GetAndStoreTokens(httpContext);
                    httpContext.Response.Cookies.Append("XSRF-TOKEN", tokens.RequestToken,
                                                        new CookieOptions()
                    {
                        HttpOnly = false
                    });
                }
                return(next(httpContext));
            });
        }
Exemple #16
0
        public async Task BuyLicense_checkIfCashAmmountDecreaseAndPointsIncrease_Expect1000CashAnd3250Points()
        {
            //Arrange
            var optionsBuilder = new DbContextOptionsBuilder <FabricaDBContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new FabricaDBContext(optionsBuilder.Options);
            var creditAccountService = new CreditAccountsService(context);

            var owner = new FabricaUser()
            {
                UserName           = "******",
                NormalizedUserName = "******".ToUpper(),
                Email           = "*****@*****.**",
                NormalizedEmail = "*****@*****.**".ToUpper(),
                PasswordHash    = "123",
                SecurityStamp   = Guid.NewGuid().ToString(),
                LockoutEnabled  = true,
                FullName        = "Owner owner",
                Gender          = GenderType.Male,
                IsDeleted       = false,
            };
            await context.Users.AddAsync(owner);

            var ownerCA = new CreditAccount()
            {
                AccountId      = "2000",
                AccountOwnerId = owner.Id,
                AccountOwner   = owner,
                CardNumber     = "2334-3344-3345-2333",
                AuthNumber     = "2333",
                Points         = 2000,
                Cash           = 1500,
            };
            await context.CreditAccounts.AddAsync(ownerCA);

            var licenzes = new List <Licenze>()
            {
                new Licenze()
                {
                    Name        = "Basic",
                    Type        = LicenzeType.Basic,
                    Price       = 30,
                    bonusPoints = 75,
                },
                new Licenze()
                {
                    Name        = "Advanced",
                    Type        = LicenzeType.Advanced,
                    Price       = 100,
                    bonusPoints = 250,
                },
                new Licenze()
                {
                    Name        = "Expert",
                    Type        = LicenzeType.Expert,
                    Price       = 500,
                    bonusPoints = 1250,
                },
            };
            await context.Licenzes.AddRangeAsync(licenzes);

            await context.SaveChangesAsync();

            //Act
            foreach (var license in licenzes)
            {
                if (license.Type == LicenzeType.Expert)
                {
                    await creditAccountService.BuyLicense(owner.Id, license.Type.ToString());
                }
            }

            var creditAccountRefreshed = context.CreditAccounts
                                         .FirstOrDefaultAsync(x => x.AccountId == ownerCA.AccountId)
                                         .Result;

            //Assert
            var expectedCash   = 1000;
            var expectedPoints = 3250;
            var cash           = creditAccountRefreshed.Cash;
            var points         = creditAccountRefreshed.Points;

            Assert.Equal(expectedCash, cash);
            Assert.Equal(expectedPoints, points);
        }
Exemple #17
0
 public OrdersService(FabricaDBContext context) : base(context)
 {
 }
Exemple #18
0
 public PropsService(FabricaDBContext context) : base(context)
 {
 }