Ejemplo n.º 1
0
        public void Should_Return_Created_If_Created()
        {
            var fakePostRepository = new Mock<IPostRepository>();
            var fakePost = new Post();
            fakePostRepository.Setup(x => x.Create(It.IsAny<Post>())).Returns(fakePost);

            var browser = new Browser(
                cfg =>
                {
                    cfg.Module<BlogModule>();
                    cfg.Dependencies<IPostRepository>(fakePostRepository.Object);
                    cfg.RequestStartup((container, pipelines, context) =>
                    {
                        context.CurrentUser = new UserIdentity {UserName = "******"};
                    });
                });

            var result = browser.Post("/", with =>
            {
                with.HttpRequest();
                with.FormValue("Content", "Test Content");
            });

            Assert.Equal(HttpStatusCode.Created, result.StatusCode);
        }
Ejemplo n.º 2
0
        public async Task<Post> Update(Post post)
        {
            if (post == null)
            {
                return null;
            }

            bool result;
            using (var conn = new SQLiteConnection(Connectionstring))
            {
                conn.Open();

                result = await conn.UpdateAsync(post);

                conn.Close();
            }

            return result ? post : null;
        }
Ejemplo n.º 3
0
        public Post Create(Post post)
        {
            if (post == null)
            {
                return null;
            }

            using (var conn = new SQLiteConnection(Connectionstring))
            {
                conn.Open();

                var postid = conn.Insert(post);
                post.Id = (int)postid;

                conn.Close();
            }

            return post.Id > 0 ? post : null;
        }
Ejemplo n.º 4
0
        public void Should_Return_Unauthorized_If_InvalidUser_Creating()
        {
            var fakePostRepository = new Mock<IPostRepository>();
            var fakePost = new Post();
            fakePostRepository.Setup(x => x.Create(fakePost)).Returns((Post)null);

            var browser = new Browser(
                cfg =>
                {
                    cfg.Module<BlogModule>();
                    cfg.Dependencies<IPostRepository>(fakePostRepository.Object);
                });

            var result = browser.Post("/", with =>
            {
                with.HttpRequest();
                with.FormValue("Content", "Test Content");
            });

            Assert.Equal(HttpStatusCode.Unauthorized, result.StatusCode);
        }