예제 #1
0
 private async Task SaveBug(BugEntity model)
 {
     try
     {
         _context.Bugs.Add(model);
         await _context.SaveChangesAsync();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error while saving bug: " + ex.Message);
     }
 }
예제 #2
0
        public async Task <BugEntity> Create(BugEntity bugEntity)
        {
            using (var ctx = _dbContextFactory.CreateBugDbContext())
            {
                bugEntity.CreationDate         = DateTime.UtcNow;
                bugEntity.LastModificationDate = DateTime.UtcNow;

                var updatedButEntity = ctx.Bugs.Add(bugEntity);
                await ctx.SaveChangesAsync();

                return(updatedButEntity);
            }
        }
예제 #3
0
        public async Task GivenTheServer_WhenGetBugRequestIsProcessedAndBugDoesNotExist_ReturnsNotFound()
        {
            // Arrange
            var       id        = TestUtility.FixtureInstance.Create <long>();
            BugEntity bugEntity = null;

            The <IBugRepository>().Setup(x => x.Get(id)).Returns(Task.FromResult(bugEntity));

            Target.SetupRequest(HttpMethod.Get, TestUtility.CreateUri());

            // Act
            var result = await Target.Get(id) as NotFoundResult;

            // Assert
            result.Should().NotBeNull();
        }
예제 #4
0
        public async Task <BugEntity> Update(BugEntity bugEntity)
        {
            using (var ctx = _dbContextFactory.CreateBugDbContext())
            {
                var existingBug = await ctx.Bugs.SingleOrDefaultAsync(x => x.Id == bugEntity.Id);

                if (existingBug == null)
                {
                    return(null);
                }

                existingBug.LastModificationDate = DateTime.UtcNow;
                existingBug.Title       = bugEntity.Title;
                existingBug.Description = bugEntity.Description;

                await ctx.SaveChangesAsync();

                return(existingBug);
            }
        }
예제 #5
0
 public static void SetupMap(this Mock <IMapper> mock, Bug bug, BugEntity bugEntity)
 {
     mock.Setup(x => x.Map <Bug>(It.Is <BugEntity>(p => p.Id == bugEntity.Id))).Returns(bug);
     mock.Setup(x => x.Map <BugEntity>(It.Is <Bug>(p => p.Id == bug.Id))).Returns(bugEntity);
 }