Пример #1
0
        public async Task DeleteCategory()
        {
            var options = new DbContextOptionsBuilder <ApplicationUserDbContext>().UseInMemoryDatabase(databaseName: "Test_DeleteCategory").Options;
            MapperConfiguration mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMapperProfile());
            });
            IMapper mapper = mappingConfig.CreateMapper();
            ApplicationResult <CategoryDto> resultCreate = new ApplicationResult <CategoryDto>();

            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                resultCreate = await CreateCategory(inMemoryContext, mapper);
            }

            ApplicationResult resultDelete = new ApplicationResult();

            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                // create servis duzgun calisti mi?
                Assert.True(resultCreate.Succeeded);
                Assert.NotNull(resultCreate.Result);
                // delete servisi calistir
                var service = new CategoryService(inMemoryContext, mapper);
                resultDelete = await service.Delete(resultCreate.Result.Id);
            }
            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                // delete servis kontrolu
                Assert.True(resultDelete.Succeeded);
                Assert.Null(resultDelete.ErrorMessage);
                // delete basarilimi db den kontrol
                Assert.Equal(0, await inMemoryContext.Categories.CountAsync());
            }
        }
Пример #2
0
 public AccountController(
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     ITokenService tokenService,
     ApplicationUserDbContext dbContext,
     IMapper mapper,
     IRandomPasswordHelper randomPasswordHelper,
     IExternalAuthService <FacebookResponse> facebookService,
     IExternalAuthService <GoogleResponse> googleService,
     ILogger <AccountController> logger,
     IHostingEnvironment hostingEnvironment,
     IChallengeUserSyncService challengeUserSyncService,
     ILoyaltySyncService loyaltySyncService,
     ILoyaltyService loyaltyService,
     IGameUserSyncService gameUserSyncService,
     IImageService imageService,
     IStringLocalizer <AccountController> localizer)
 {
     _userManager              = userManager;
     _signInManager            = signInManager;
     _tokenService             = tokenService;
     _dbContext                = dbContext;
     _mapper                   = mapper;
     _randomPasswordHelper     = randomPasswordHelper;
     _facebookService          = facebookService;
     _googleService            = googleService;
     _logger                   = logger;
     _hostingEnvironment       = hostingEnvironment;
     _challengeUserSyncService = challengeUserSyncService;
     _loyaltySyncService       = loyaltySyncService;
     _loyaltyService           = loyaltyService;
     _gameUserSyncService      = gameUserSyncService;
     _imageService             = imageService;
     _localizer                = localizer;
 }
Пример #3
0
 public FanficController(IUnitOfWork unitOfWork, IMapper mapper, UserManager <ApplicationUser> userManager, ApplicationUserDbContext a)
 {
     _unitOfWork  = unitOfWork;
     _mapper      = mapper;
     _userManager = userManager;
     _a           = a;
 }
        // verileri kayit ederken db ayarlarinin ayni dbname icerisinde olduguna dikkat edin, eger db nameler farkliysa test verileri farkli veri tabanlarina kayit olur. tum test metotlarinda(Fact'lerde) ayri dbName'ler verilmesinin sebebi budur.
        public async Task <List <ApplicationResult <PostDto> > > CreatePost(List <CreatePostInput> fakePostList, string postDbName)
        {
            var options = new DbContextOptionsBuilder <ApplicationUserDbContext>().UseInMemoryDatabase(databaseName: postDbName).Options;
            MapperConfiguration mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMapperProfile());
            });
            IMapper mapper = mappingConfig.CreateMapper();
            ApplicationResult <CategoryDto> result = new ApplicationResult <CategoryDto>();

            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                CategoryServiceShould categoryShould = new CategoryServiceShould();
                result = await categoryShould.CreateCategory(inMemoryContext, mapper);

                await categoryShould.AssertCreatedCategory(inMemoryContext, result);
            }

            List <ApplicationResult <PostDto> > createdPostResulList = new List <ApplicationResult <PostDto> >();

            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                var service = new PostService(inMemoryContext, mapper);
                foreach (var item in fakePostList)
                {
                    item.CategoryId = result.Result.Id;
                    createdPostResulList.Add(await service.Create(item));
                }
            }
            return(createdPostResulList);
        }
Пример #5
0
 public ProductService(ApplicationUserDbContext context, UserManager <ApplicationUser> userManager,
                       IMapper mapper)
 {
     _context     = context;
     _userManager = userManager;
     _mapper      = mapper;
 }
Пример #6
0
        public void Given_AccountsRepo_When_AddIsCalled_Then_CountIs1()
        {
            RunOnDatabase(async context =>
            {
                //Arrange
                var options = new DbContextOptionsBuilder <ApplicationUserDbContext>()
                              .UseInMemoryDatabase("FiiAdmissionDb")
                              .Options;
                var newContext         = new ApplicationUserDbContext(options);
                var accountsRepository = new JobSeekerRepository(newContext);
                var jobSeeker          = new JobSeeker
                {
                    Id       = Guid.NewGuid(),
                    Identity = new AppUser
                    {
                        FirstName = "Someone",
                        LastName  = "Anyone"
                    },
                    IdentityId = Guid.NewGuid().ToString()
                };

                //Act
                await accountsRepository.AddAsync(jobSeeker);

                //Assert
                var res = await accountsRepository.GetAll();
                res.Count.Should().Be(1);
            });
        }
        async Task AssertCreatedPostAsync(ApplicationUserDbContext inMemoryContext, List <ApplicationResult <PostDto> > resultList, List <CreatePostInput> fakePostList)
        {
            foreach (var fakePost in fakePostList)
            {
                ApplicationResult <PostDto> foundResult = resultList.Find(x =>
                                                                          x.Result.Content == fakePost.Content &&
                                                                          x.Result.Title == fakePost.Title &&
                                                                          x.Result.UrlName == fakePost.UrlName &&
                                                                          x.Result.CreatedBy == fakePost.CreatedBy &&
                                                                          x.Result.CreatedById == fakePost.CreatedById
                                                                          );
                Assert.True(foundResult.Succeeded);
                Assert.NotNull(foundResult.Result);
                var item = await inMemoryContext.Posts.FirstAsync(x =>
                                                                  x.Content == fakePost.Content &&
                                                                  x.Title == fakePost.Title &&
                                                                  x.UrlName == fakePost.UrlName &&
                                                                  x.CreatedBy == fakePost.CreatedBy &&
                                                                  x.CreatedById == fakePost.CreatedById
                                                                  );

                Assert.Equal(fakePost.CreatedBy, item.CreatedBy);
                Assert.Equal(fakePost.Title, item.Title);
                Assert.Equal(fakePost.UrlName, item.UrlName);
                Assert.Equal(fakePost.Content, item.Content);
            }
            Assert.Equal(fakePostList.Count, await inMemoryContext.Posts.CountAsync());
        }
        public async Task CreateNewPost()
        {
            string postDbName  = "postDbCreateNewPost";
            var    optionsPost = new DbContextOptionsBuilder <ApplicationUserDbContext>().UseInMemoryDatabase(databaseName: postDbName).Options;

            List <CreatePostInput> fakePostList = new List <CreatePostInput>
            {
                new CreatePostInput
                {
                    Content     = "Lorem Ipsum Dolor Sit Amet",
                    Title       = "Lorem Ipsum Dolor",
                    UrlName     = "lorem-ipsum-dolor",
                    CreatedBy   = "Tester1",
                    CreatedById = Guid.NewGuid().ToString()
                }
            };


            var resultList = await CreatePost(fakePostList, postDbName);

            using (var inMemoryContext = new ApplicationUserDbContext(optionsPost))
            {
                await AssertCreatedPostAsync(inMemoryContext, resultList, fakePostList);
            }
        }
 public ManageController(UserManager <ApplicationUser> userManager,
                         RoleManager <IdentityRole> roleManager, ApplicationUserDbContext context)
 {
     _userManager = userManager;
     _roleManager = roleManager;
     _context     = context;
 }
Пример #10
0
 // constructor
 public BazaarListItemServiceShould()
 {
     bazaarListId      = 1;
     options           = new DbContextOptionsBuilder <ApplicationUserDbContext>().UseInMemoryDatabase(databaseName: "BazaarListItemService_TestDb").Options;
     inMemoryDbContext = new ApplicationUserDbContext(options);
     service           = new BazaarListItemService(inMemoryDbContext);
 }
Пример #11
0
        public async Task CreateNewCategory()
        {
            var options = new DbContextOptionsBuilder <ApplicationUserDbContext>().UseInMemoryDatabase(databaseName: "Test_NewCategoryCreate").Options;
            MapperConfiguration mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMapperProfile());
            });
            IMapper mapper = mappingConfig.CreateMapper();
            ApplicationResult <CategoryDto> result = new ApplicationResult <CategoryDto>();

            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                result = await CreateCategory(inMemoryContext, mapper);
            }

            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                Assert.True(result.Succeeded);
                Assert.NotNull(result.Result);
                Assert.Equal(1, await inMemoryContext.Categories.CountAsync());
                var item = await inMemoryContext.Categories.FirstOrDefaultAsync();

                Assert.Equal("Tester1", item.CreatedBy);
                Assert.Equal("Lorem Ipsum", item.Name);
                Assert.Equal("lorem-ipsum", item.UrlName);
                Assert.Equal(result.Result.CreatedById, item.CreatedById);
            }
        }
Пример #12
0
 public UserController(ApplicationUserDbContext context, UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, IConfiguration configuration)
 {
     _context       = context;
     _userManager   = userManager;
     _signInManager = signInManager;
     _configuration = configuration;
 }
Пример #13
0
        public async Task UpdateCategory()
        {
            var options = new DbContextOptionsBuilder <ApplicationUserDbContext>().UseInMemoryDatabase(databaseName: "Test_UpdateCategory").Options;
            MapperConfiguration mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMapperProfile());
            });
            IMapper mapper = mappingConfig.CreateMapper();
            ApplicationResult <CategoryDto> resultCreate = new ApplicationResult <CategoryDto>();

            // bir yeni kategori olustur
            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                resultCreate = await CreateCategory(inMemoryContext, mapper);
            }

            ApplicationResult <CategoryDto> resultUpdate = new ApplicationResult <CategoryDto>();

            // yeni kategori olustu mu test et ve var olan kategoriyi guncelle
            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                // create servis duzgun calisti mi?
                Assert.True(resultCreate.Succeeded);
                Assert.NotNull(resultCreate.Result);
                // update islemini yap!

                var item = await inMemoryContext.Categories.FirstOrDefaultAsync();

                var service    = new CategoryService(inMemoryContext, mapper);
                var fakeUpdate = new UpdateCategoryInput
                {
                    Id           = item.Id,
                    CreatedById  = item.CreatedById,
                    ModifiedById = Guid.NewGuid().ToString(),
                    ModifiedBy   = "Tester2",
                    Name         = "Lorem Ipsum Dolor",
                    UrlName      = "lorem-ipsum-dolor"
                };
                // update servisi calistir
                resultUpdate = await service.Update(fakeUpdate);
            }
            // update basarili mi kontrol et
            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                // contextte kategori var mi?
                Assert.Equal(1, await inMemoryContext.Categories.CountAsync());
                // update servis duzgun calisti mi?
                Assert.True(resultUpdate.Succeeded);
                Assert.NotNull(resultUpdate.Result);
                // update islem basarili mi (context ten gelen veri ile string ifadeleri karsilastir)
                var item = await inMemoryContext.Categories.FirstAsync();

                Assert.Equal("Tester1", item.CreatedBy);
                Assert.Equal("Tester2", item.ModifiedBy);
                Assert.Equal("Lorem Ipsum Dolor", item.Name);
                Assert.Equal("lorem-ipsum-dolor", item.UrlName);
                Assert.Equal(resultUpdate.Result.ModifiedById, item.ModifiedById);
            }
        }
        public async Task UpdatePost()
        {
            string postDbName  = "postDbUpdatePost";
            var    optionsPost = new DbContextOptionsBuilder <ApplicationUserDbContext>().UseInMemoryDatabase(databaseName: postDbName).Options;
            MapperConfiguration mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMapperProfile());
            });
            IMapper mapper = mappingConfig.CreateMapper();
            List <CreatePostInput> fakePostList = new List <CreatePostInput>
            {
                new CreatePostInput
                {
                    Content     = "Lorem Ipsum Dolor Sit Amet",
                    Title       = "Lorem Ipsum Dolor",
                    UrlName     = "lorem-ipsum-dolor",
                    CreatedBy   = "Tester1",
                    CreatedById = Guid.NewGuid().ToString()
                }
            };
            ApplicationResult <PostDto>         resultUpdatePost = new ApplicationResult <PostDto>();
            List <ApplicationResult <PostDto> > resultList       = await CreatePost(fakePostList, postDbName);

            using (var inMemoryContext = new ApplicationUserDbContext(optionsPost))
            {
                await AssertCreatedPostAsync(inMemoryContext, resultList, fakePostList);

                var item = await inMemoryContext.Posts.FirstOrDefaultAsync();

                PostService     service    = new PostService(inMemoryContext, mapper);
                UpdatePostInput fakeUpdate = new UpdatePostInput
                {
                    Id           = item.Id,
                    CreatedById  = item.CreatedById,
                    ModifiedById = Guid.NewGuid().ToString(),
                    ModifiedBy   = "Tester1 Updated",
                    Content      = "Lorem Ipsum Dolor Sit Amet Updated",
                    Title        = "Lorem Ipsum Dolor Updated",
                    UrlName      = "lorem-ipsum-dolor-updated"
                };
                resultUpdatePost = await service.Update(fakeUpdate);
            }

            using (var inMemoryContext = new ApplicationUserDbContext(optionsPost))
            {
                Assert.Equal(1, await inMemoryContext.Posts.CountAsync());
                Assert.True(resultUpdatePost.Succeeded);
                Assert.NotNull(resultUpdatePost.Result);
                var item = await inMemoryContext.Posts.FirstAsync();

                Assert.Equal("Tester1", item.CreatedBy);
                Assert.Equal("Tester1 Updated", item.ModifiedBy);
                Assert.Equal("Lorem Ipsum Dolor Sit Amet Updated", item.Content);
                Assert.Equal("Lorem Ipsum Dolor Updated", item.Title);
                Assert.Equal("lorem-ipsum-dolor-updated", item.UrlName);
                Assert.Equal(resultUpdatePost.Result.ModifiedById, item.ModifiedById);
            }
        }
        public async Task GetAllPosts()
        {
            string postDbName = "postDbGetAllPost";
            MapperConfiguration mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMapperProfile());
            });
            IMapper mapper      = mappingConfig.CreateMapper();
            var     optionsPost = new DbContextOptionsBuilder <ApplicationUserDbContext>().UseInMemoryDatabase(databaseName: postDbName).Options;
            List <CreatePostInput> fakePostList = new List <CreatePostInput>
            {
                new CreatePostInput
                {
                    Content     = "Lorem Ipsum Dolor Sit Amet",
                    Title       = "Lorem Ipsum Dolor",
                    UrlName     = "lorem-ipsum-dolor",
                    CreatedBy   = "Tester1",
                    CreatedById = Guid.NewGuid().ToString()
                },
                new CreatePostInput
                {
                    Content     = "Lorem Ipsum Dolor Sit Amet2",
                    Title       = "Lorem Ipsum Dolor2",
                    UrlName     = "lorem-ipsum-dolor2",
                    CreatedBy   = "Tester2",
                    CreatedById = Guid.NewGuid().ToString()
                }
            };
            var resultList = await CreatePost(fakePostList, postDbName);

            ApplicationResult <List <PostDto> > resultGetAll = new ApplicationResult <List <PostDto> >();

            using (var inMemoryContext = new ApplicationUserDbContext(optionsPost))
            {
                await AssertCreatedPostAsync(inMemoryContext, resultList, fakePostList);

                var service = new PostService(inMemoryContext, mapper);
                resultGetAll = await service.GetAll();
            }
            using (var inMemoryContext = new ApplicationUserDbContext(optionsPost))
            {
                foreach (var fakePost in fakePostList)
                {
                    PostDto foundResult = resultGetAll.Result.Find(x =>
                                                                   x.Content == fakePost.Content &&
                                                                   x.Title == fakePost.Title &&
                                                                   x.UrlName == fakePost.UrlName &&
                                                                   x.CreatedBy == fakePost.CreatedBy &&
                                                                   x.CreatedById == fakePost.CreatedById
                                                                   );
                    Assert.NotNull(foundResult);
                }

                Assert.Equal(fakePostList.Count, await inMemoryContext.Posts.CountAsync());
                Assert.True(resultGetAll.Succeeded);
                Assert.NotNull(resultGetAll.Result);
            }
        }
Пример #16
0
        public Tenant GetTenantById(int id)
        {
            using (var context = ApplicationUserDbContext <ApplicationUser> .Create())
            {
                var tenant = context.Tenants.Where(x => x.Id == id).SingleOrDefault();

                return(tenant);
            }
        }
Пример #17
0
 /// <summary>
 /// Checking database for roles
 /// </summary>
 /// <param name="serviceProvider"></param>
 public static void SeedData(IServiceProvider serviceProvider)
 {
     // looking at our database
     using (var dbContext = new ApplicationUserDbContext(serviceProvider.GetRequiredService <DbContextOptions <ApplicationUserDbContext> >()))
     {
         dbContext.Database.EnsureCreated();
         AddRoles(dbContext);
     }
 }
Пример #18
0
        public Tenant GetTenantByName(string name)
        {
            using (var context = ApplicationUserDbContext <ApplicationUser> .Create())
            {
                var tenant = context.Tenants.Where(x => x.Name.Equals((name == null || name == string.Empty ? "System" : name), StringComparison.InvariantCultureIgnoreCase)).SingleOrDefault();

                return(tenant);
            }
        }
Пример #19
0
 public HomeController(ILogger <HomeController> logger, SignInManager <ApplicationUser> signInManager, UserManager <ApplicationUser> userManager,
                       ApplicationUserDbContext applicationUserDbContext, IWebHostEnvironment webHostEnvironment, IUnitOfWork unitOfWork)
 {
     _logger                   = logger;
     _signInManager            = signInManager;
     _userManager              = userManager;
     _applicationUserDbContext = applicationUserDbContext;
     _webHostEnvironment       = webHostEnvironment;
     _unitOfWork               = unitOfWork;
 }
Пример #20
0
        public async Task <Tenant> SaveTenantAsync(Tenant tenant)
        {
            using (var context = ApplicationUserDbContext <ApplicationUser> .Create())
            {
                context.Tenants.Add(tenant);
                await context.SaveChangesAsync();

                return(tenant);
            }
        }
Пример #21
0
        public ApplicationUser FindTenantUser(string tenant, string username, string password)
        {
            var context = ApplicationUserDbContext <ApplicationUser> .Create();

            var user = context.Users
                       .Include(x => x.Tenant)
                       .Where(x => x.UserName.Equals(username, StringComparison.InvariantCultureIgnoreCase))
                       .SingleOrDefault(x => x.Tenant.Name.Equals(tenant, StringComparison.InvariantCultureIgnoreCase));

            return(user);
        }
Пример #22
0
        public async Task AssertCreatedCategory(ApplicationUserDbContext inMemoryContext, ApplicationResult <CategoryDto> resultCreate)
        {
            Assert.True(resultCreate.Succeeded);
            Assert.NotNull(resultCreate.Result);
            Assert.Equal(1, await inMemoryContext.Categories.CountAsync());
            var item = await inMemoryContext.Categories.FirstOrDefaultAsync();

            Assert.Equal("Tester1", item.CreatedBy);
            Assert.Equal("Lorem Ipsum", item.Name);
            Assert.Equal("lorem-ipsum", item.UrlName);
            Assert.Equal(resultCreate.Result.CreatedById, item.CreatedById);
        }
Пример #23
0
        public async Task AssertCreatedCategory(ApplicationUserDbContext inMemoryContext, ApplicationResult <CategoryDto> resultCreate, CreateCategoryInput fakeCategory)
        {
            Assert.True(resultCreate.Succeeded);
            Assert.NotNull(resultCreate.Result);
            Assert.Equal(1, await inMemoryContext.Categories.CountAsync());
            var item = await inMemoryContext.Categories.FirstOrDefaultAsync();

            Assert.Equal(fakeCategory.CreatedBy, item.CreatedBy);
            Assert.Equal(fakeCategory.Name, item.Name);
            Assert.Equal(fakeCategory.UrlName, item.UrlName);
            Assert.Equal(resultCreate.Result.CreatedById, item.CreatedById);
        }
Пример #24
0
        public async Task CreatePost()
        {
            var options = new DbContextOptionsBuilder <ApplicationUserDbContext>().UseInMemoryDatabase(databaseName: "Test_PostCreate").Options;
            MapperConfiguration mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMapperProfile());
            });
            IMapper mapper = mappingConfig.CreateMapper();
            ApplicationResult <CategoryDto> resultCreateCategory = new ApplicationResult <CategoryDto>();

            // create category
            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                CategoryServiceShould categoryShould = new CategoryServiceShould();
                resultCreateCategory = await categoryShould.CreateCategory(inMemoryContext, mapper);
            }
            // check create category
            ApplicationResult <PostDto> resultPost = new ApplicationResult <PostDto>();

            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                CategoryServiceShould categoryShould = new CategoryServiceShould();
                await categoryShould.AssertCreatedCategory(inMemoryContext, resultCreateCategory);

                // create post
                var             service  = new PostService(inMemoryContext, mapper);
                CreatePostInput fakePost = new CreatePostInput
                {
                    CategoryId  = resultCreateCategory.Result.Id,
                    Content     = "Lorem Ipsum Dolor Sit Amet",
                    Title       = "Lorem Ipsum Dolor",
                    UrlName     = "lorem-ipsum-dolor",
                    CreatedBy   = "Tester1",
                    CreatedById = Guid.NewGuid().ToString()
                };
                resultPost = await service.Create(fakePost);
            }
            // check post create service
            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                Assert.True(resultPost.Succeeded);
                Assert.NotNull(resultPost.Result);
                Assert.Equal(1, await inMemoryContext.Posts.CountAsync());
                var item = await inMemoryContext.Posts.FirstAsync();

                Assert.Equal("Tester1", item.CreatedBy);
                Assert.Equal("Lorem Ipsum Dolor", item.Title);
                Assert.Equal("lorem-ipsum-dolor", item.UrlName);
                Assert.Equal("Lorem Ipsum Dolor Sit Amet", item.Content);
                Assert.Equal(resultCreateCategory.Result.Id, item.CategoryId);
            }
        }
        // Category alaninin null gelmesinin sebebi onun bilgisin baska bir veritabaninda tutulmasidir. Bu sebeple veritabani ismini ayni yaptik ve artik null gelmiyor.
        public async Task GetPost()
        {
            string postDbName = "postDbGetPost";
            MapperConfiguration mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMapperProfile());
            });
            IMapper mapper      = mappingConfig.CreateMapper();
            var     optionsPost = new DbContextOptionsBuilder <ApplicationUserDbContext>().UseInMemoryDatabase(databaseName: postDbName).Options;
            ApplicationResult <PostDto> resultGet    = new ApplicationResult <PostDto>();
            List <CreatePostInput>      fakePostList = new List <CreatePostInput>
            {
                new CreatePostInput
                {
                    Content     = "Lorem Ipsum Dolor Sit Amet",
                    Title       = "Lorem Ipsum Dolor",
                    UrlName     = "lorem-ipsum-dolor",
                    CreatedBy   = "Tester1",
                    CreatedById = Guid.NewGuid().ToString()
                }
            };
            var resultList = await CreatePost(fakePostList, postDbName);

            using (var inMemoryContext = new ApplicationUserDbContext(optionsPost))
            {
                await AssertCreatedPostAsync(inMemoryContext, resultList, fakePostList);
            }
            using (var inMemoryContext = new ApplicationUserDbContext(optionsPost))
            {
                var service = new PostService(inMemoryContext, mapper);
                resultGet = await service.Get(resultList[0].Result.Id);
            }
            using (var inMemoryContext = new ApplicationUserDbContext(optionsPost))
            {
                // get servis dogru calisti mi kontrolu
                Assert.True(resultGet.Succeeded);
                Assert.NotNull(resultGet.Result);
                Assert.Equal("Lorem Ipsum Dolor Sit Amet", resultGet.Result.Content);
                Assert.Equal("Lorem Ipsum Dolor", resultGet.Result.Title);
                Assert.Equal("lorem-ipsum-dolor", resultGet.Result.UrlName);

                var optionsCategory = new DbContextOptionsBuilder <ApplicationUserDbContext>().UseInMemoryDatabase(databaseName: postDbName).Options;
                using (var inMemoryContextCategory = new ApplicationUserDbContext(optionsCategory))
                {
                    Assert.Equal(1, await inMemoryContextCategory.Categories.CountAsync());
                    var item = await inMemoryContextCategory.Categories.FirstAsync();

                    Assert.Equal("Lorem Ipsum", item.Name);
                    Assert.Equal("lorem-ipsum", item.UrlName);
                }
            }
        }
Пример #26
0
        /// <summary>
        /// This method adds a role to a user
        /// </summary>
        /// <param name="context"></param>
        private static void AddRoles(ApplicationUserDbContext context)
        {
            if (context.Roles.Any())
            {
                return;
            }

            foreach (var role in Roles)
            {
                context.Roles.Add(role);
                context.SaveChanges();
            }
        }
Пример #27
0
        public async Task <ApplicationResult <CategoryDto> > CreateCategory(ApplicationUserDbContext inMemoryContext, IMapper mapper)
        {
            var service = new CategoryService(inMemoryContext, mapper);
            CreateCategoryInput fakeCategory = new CreateCategoryInput
            {
                CreatedById = Guid.NewGuid().ToString(), // sahte kullanici
                CreatedBy   = "Tester1",
                Name        = "Lorem Ipsum",
                UrlName     = "lorem-ipsum"
            };

            return(await service.Create(fakeCategory));
        }
Пример #28
0
        /// <summary>
        /// Create the dbcontext.
        /// </summary>
        /// <param name="args">An array of arguments passed to the create dbcontext.</param>
        /// <returns>Returns the dbcontext.</returns>
        public ApplicationUserDbContext CreateDbContext(string[] args)
        {
            // Create the dbcontext.  Get the settings from the appsettings.json file.
            ApplicationUserDbContext dbContext = new ApplicationUserDbContext(new DbContextOptionsBuilder <ApplicationUserDbContext>().UseSqlServer(
                                                                                  new ConfigurationBuilder()
                                                                                  .AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), $"appsettings.json"))
                                                                                  .Build()
                                                                                  .GetConnectionString("DatabaseConnection")
                                                                                  ).Options);

            // Applies any migrations to the database and if it doesn't exist this will create it.
            dbContext.Database.Migrate();

            // Return the dbcontext.
            return(dbContext);
        }
Пример #29
0
        public void Given_AccountsRepo_When_GetAllIsCalled_Then_CountIs0()
        {
            RunOnDatabase(async context =>
            {
                //Arrange
                var options = new DbContextOptionsBuilder <ApplicationUserDbContext>()
                              .UseInMemoryDatabase("FiiAdmissionDb")
                              .Options;
                var newContext         = new ApplicationUserDbContext(options);
                var accountsRepository = new JobSeekerRepository(newContext);

                //Act

                //Assert
                var res = await accountsRepository.GetAll();
                res.Count.Should().Be(0);
            });
        }
Пример #30
0
        public async Task GetCategory()
        {
            var options = new DbContextOptionsBuilder <ApplicationUserDbContext>().UseInMemoryDatabase(databaseName: "Test_GetCategory").Options;
            MapperConfiguration mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMapperProfile());
            });
            IMapper mapper = mappingConfig.CreateMapper();

            ApplicationResult <CategoryDto> resultCreate = new ApplicationResult <CategoryDto>();

            // Bir kategori olustur
            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                resultCreate = await CreateCategory(inMemoryContext, mapper);
            }
            ApplicationResult <CategoryDto> resultGet = new ApplicationResult <CategoryDto>();

            // create servis dogru calistimi kontrol et ve get servisi calistir
            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                // create servis duzgun calisti mi?
                Assert.True(resultCreate.Succeeded);
                Assert.NotNull(resultCreate.Result);

                // get islemini calistir
                var service = new CategoryService(inMemoryContext, mapper);
                resultGet = await service.Get(resultCreate.Result.Id);
            }
            // get servis dogru calistimi kontrol et
            using (var inMemoryContext = new ApplicationUserDbContext(options))
            {
                // get servis dogru calisti mi kontrolu
                Assert.True(resultGet.Succeeded);
                Assert.NotNull(resultGet.Result);
                Assert.Equal("Lorem Ipsum", resultGet.Result.Name);
                Assert.Equal("lorem-ipsum", resultGet.Result.UrlName);
                Assert.Equal(1, await inMemoryContext.Categories.CountAsync());
                var item = await inMemoryContext.Categories.FirstAsync();

                Assert.Equal("Lorem Ipsum", item.Name);
                Assert.Equal("lorem-ipsum", item.UrlName);
            }
        }