예제 #1
0
        public void UpdateBoard_ExceptionTrownByExternalCode_ExceptionHandled()
        {
            var ctxMocked = new Mock <ApiDbContext>(new DbContextOptionsBuilder <ApiDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);

            ctxMocked.Setup(x => x.Find(It.IsAny <Type>())).Throws <Exception>();
            var boardStorage = new BoardStorage(ctxMocked.Object);

            var updateResult = boardStorage.UpdateBoardTitleAsync(new Board
            {
                Id    = Guid.NewGuid(),
                Title = "test"
            });

            Assert.False(updateResult.Result.IsSuccess);
            Assert.Contains("Updating the board unexpectedly failed", updateResult.Result.ErrorReason);
        }
예제 #2
0
        public void UpdateBoard_UpdateExistentBoard_BoardUpdated()
        {
            var boardToUpdate = new Board {
                Title = "Title", Id = Guid.NewGuid()
            };
            var ctx = GetContext();

            ctx.Boards.Add(boardToUpdate);
            ctx.SaveChanges();
            boardToUpdate.Title = "New Title";
            var boardStorage = new BoardStorage(ctx);

            var updateRedult = boardStorage.UpdateBoardTitleAsync(boardToUpdate);

            Assert.NotNull(updateRedult);
            Assert.True(updateRedult.Result.IsSuccess);
            var boardFromDb = ctx.Boards.Find(updateRedult.Result.ResultEntity);

            Assert.NotNull(boardFromDb);
            Assert.Equal("New Title", boardFromDb.Title);
        }