예제 #1
0
 public UserController(
     BlogsDataBaseContext context,
     IMapper mapper,
     UserManager <User> userManager,
     ILogger <UserController> logger) : base(context, mapper, logger)
 {
     this.userManager = userManager;
 }
예제 #2
0
 public ControllerCommon(
     BlogsDataBaseContext context,
     IMapper mapper,
     ILogger <T> logger)
 {
     this.context = context;
     this.mapper  = mapper;
     this.logger  = logger;
 }
예제 #3
0
 public AuthenticationController(
     BlogsDataBaseContext context,
     IMapper mapper,
     UserManager <User> userManager,
     ITokenService tokenService,
     ILogger <AuthenticationController> logger) : base(context, mapper, logger)
 {
     this.userManager  = userManager;
     this.tokenService = tokenService;
 }
예제 #4
0
        public static DbContextOptions <BlogsDataBaseContext> CreateInMemoryDatabase()
        {
            var options = new DbContextOptionsBuilder <BlogsDataBaseContext>()
                          .UseInMemoryDatabase(databaseName: "Mock DB")
                          .Options;

            // setup
            using (var ctx = new BlogsDataBaseContext(options))
                AddItems(ctx);

            return(options);
        }
예제 #5
0
 public static void AddItems(BlogsDataBaseContext ctx)
 {
     ctx.BlogPosts.Add(
         new BlogPost()
     {
         BlogId     = blogId,
         BlogPostId = postId,
         BodyText   = postText,
         HeaderText = postHeader,
         Comments   = new List <Comment>()
     });
     ctx.SaveChanges();
 }
        public async Task TestGetExistingBlogPost()
        {
            var options    = DbCreator.CreateInMemoryDatabase();
            var loggerMock = new Mock <ILogger <BlogPostsController> >();
            var mapper     = TestMapper.CreateMapper();

            FullBlogPost post;

            using (var ctx = new BlogsDataBaseContext(options))
            {
                var controller = new BlogPostsController(ctx, mapper, loggerMock.Object);

                // act
                var result = await controller.GetBlogPost(1);

                post = result.Value;
            }

            // check
            Assert.NotNull(post);
            Assert.Equal(DbCreator.postText, post.BodyText);
            Assert.Equal(DbCreator.postHeader, post.HeaderText);
        }