コード例 #1
0
        public async Task Expect_Delete_Article_With_Tags()
        {
            var createCommand = new Create.Command
            {
                Article = new Create.ArticleData
                {
                    Title       = "Test article 666",
                    Description = "Description of the test article",
                    Body        = "Body of the test article",
                    TagList     = new[] { "tag1", "tag2" }
                }
            };

            var createdArticle = await ArticleHelpers.CreateArticle(this, createCommand);

            var articleWithTags = await ExecuteDbContextAsync(context => context.Articles
                                                              .Include(a => a.ArticleTags)
                                                              .Where(d => d.Slug == createdArticle.Slug)
                                                              .SingleOrDefaultAsync());

            var deleteCommand = new Delete.Command(createdArticle.Slug);

            var dbContext = GetDbContext();

            var handler = new Delete.Handler(dbContext);
            await handler.Handle(deleteCommand, new CancellationToken());

            var article = await ExecuteDbContextAsync(context =>
                                                      context.Articles.Where(d => d.Slug == deleteCommand.Slug).SingleOrDefaultAsync());

            Assert.Null(article);
        }
コード例 #2
0
        public void Should_Delete_License()
        {
            var context = GetDbContext();

            var modalityId = Guid.NewGuid();

            context.Modalities.Add(new Domain.Modality {
                Id = modalityId, Name = "Test Modality"
            });
            context.SaveChanges();

            var licenseId1 = Guid.NewGuid();
            var licenseId2 = Guid.NewGuid();

            context.Licenses.Add(new Domain.License {
                Id = licenseId1, Name = "Test License", DisplayName = "TL", ModalityId = modalityId
            });
            context.Licenses.Add(new Domain.License {
                Id = licenseId2, Name = "Test License 2", DisplayName = "TL2", ModalityId = modalityId
            });
            context.SaveChanges();

            var sut = new Delete.Handler(context);

            var result = sut.Handle(new Delete.Command {
                Id = licenseId1
            }, CancellationToken.None).Result;

            var licenses = context.Licenses.Where(x => x.ModalityId == modalityId).ToList();

            Assert.Single(licenses);
            Assert.Equal("Test License 2", licenses[0].Name);
        }
コード例 #3
0
        public void Should_Delete_Modality()
        {
            var context = GetDbContext();

            var modalityIdOfDeleted = Guid.NewGuid();


            context.Modalities.Add(new Modality
            {
                Id          = modalityIdOfDeleted,
                Name        = "Modality 1",
                DisplayName = "M1"
            });

            context.Modalities.Add(new Modality
            {
                Id          = Guid.NewGuid(),
                Name        = "Modality 2",
                DisplayName = "M2"
            });

            context.SaveChanges();

            var sut = new Delete.Handler(context);

            var result = sut.Handle(new Delete.Command {
                Id = modalityIdOfDeleted
            }, CancellationToken.None);

            var modalities      = context.Modalities.ToList();
            var deletedModality = modalities.FirstOrDefault(x => x.Id == modalityIdOfDeleted);

            Assert.Single(modalities);
            Assert.Null(deletedModality);
        }
コード例 #4
0
        public void Should_Fail_To_Delete_Room_With_Invalid_Id()
        {
            var context = GetDbContext();

            var locationId = Guid.NewGuid();

            context.Locations.Add(new Domain.Location {
                Id = locationId, Name = "Test Location"
            });
            context.SaveChanges();

            context.Rooms.Add(new Domain.Room {
                Id = Guid.NewGuid(), Name = "Test Room", LocationId = locationId
            });
            context.SaveChanges();


            var sut = new Delete.Handler(context);

            var nonExistingRoomId = Guid.NewGuid();

            var ex = Assert.ThrowsAsync <RestException>(() => sut.Handle(new Delete.Command {
                Id = nonExistingRoomId
            }, CancellationToken.None));

            var thrownError   = ex.Result.Errors.ToString();
            var expectedError = (new { room = "Room Not Found" }).ToString();

            Assert.Equal(expectedError, thrownError);
        }
コード例 #5
0
        public void Should_Fail_Delete_License_W_Invalid_Id()
        {
            var context    = GetDbContext();
            var modalityId = Guid.NewGuid();

            context.Modalities.Add(new Domain.Modality {
                Id = modalityId, Name = "Test Modality"
            });
            context.SaveChanges();

            var licenseId1 = Guid.NewGuid();
            var licenseId2 = Guid.NewGuid();

            context.Licenses.Add(new Domain.License {
                Id = licenseId1, Name = "Test License", DisplayName = "TL", ModalityId = modalityId
            });

            var sut = new Delete.Handler(context);

            var ex = Assert.ThrowsAsync <RestException>(() => sut.Handle(new Delete.Command {
                Id = licenseId2
            }, CancellationToken.None));

            var thrownError   = ex.Result.Errors.ToString();
            var expectedError = (new { license = "License not found" }).ToString();

            Assert.Equal(expectedError, thrownError);
        }
コード例 #6
0
        public void DeleteJob_WithEmptyJobId_ShouldThrowException()
        {
            //Arrange
            var deleteJobCommand = new Delete.Command
            {
                Id = 0
            };
            var handler = new Delete.Handler(testContext);
            //Assert
            var ex = Assert.CatchAsync <RestException>(() => handler.Handle(deleteJobCommand, CancellationToken.None));

            Assert.That(ex.Code, Is.EqualTo(HttpStatusCode.NotFound));
        }
コード例 #7
0
ファイル: DeleteTests.cs プロジェクト: saokatali/Micro-Shop
        public async void DeleteShouldDeleteTheRecord()
        {
            // Arrange
            sut = new Delete.Handler(dataContext);


            // Act
            var result = await sut.Handle(new Delete.Command {
                Id = id
            }, new System.Threading.CancellationToken());

            // Assert
            Assert.NotNull(result);
        }
コード例 #8
0
        public void Should_Delete_Shift()
        {
            var shiftIdToDelete = Create_Shift_For_Delete_Test_And_Return_Id();

            var sut = new Delete.Handler(context);

            var result = sut.Handle(new Delete.Command
            {
                Id = shiftIdToDelete
            }, CancellationToken.None);

            var shift = context.Shifts.FirstOrDefault(x => x.Id == shiftIdToDelete);

            Assert.Null(shift);
        }
コード例 #9
0
        public void DeleteJob_WithValidJobId_ShouldDeleteJob()
        {
            //Arrange
            var deleteJobCommand = new Delete.Command
            {
                Id = 1
            };
            var deleteHandler = new Delete.Handler(testContext);
            //Act
            var deleteResult = deleteHandler.Handle(deleteJobCommand, CancellationToken.None).Result;

            //Assert
            Assert.NotNull(deleteResult);
            Assert.That(deleteResult.Equals(Unit.Value));
        }
コード例 #10
0
        public void Should_Not_Delete_Shift_With_Invalid_Id()
        {
            Create_Shift_For_Delete_Test_And_Return_Id();  //do not need to use return id in this test

            var sut = new Delete.Handler(context);

            var nonExistingShiftId = Guid.NewGuid();

            var ex = Assert.ThrowsAsync <RestException>(() => sut.Handle(new Delete.Command {
                Id = nonExistingShiftId
            }, CancellationToken.None));

            var thrownError   = ex.Result.Errors.ToString();
            var expectedError = (new { shift = "Shift Not Found" }).ToString();

            Assert.Equal(expectedError, thrownError);
        }
コード例 #11
0
        public void DeleteJob_WithWrongJobId_ShouldThrowException()
        {
            //Arrange
            var deleteJobCommand = new Delete.Command
            {
                Id = 9999
            };

            var deleteHandler = new Delete.Handler(testContext);
            //Assert
            var ex = Assert.CatchAsync <Exception>(() => deleteHandler.Handle(deleteJobCommand, CancellationToken.None));

            if (ex.GetType().Equals(typeof(Exception)))
            {
                Assert.That(ex.Message, Is.EqualTo("problem saving changes"));
            }
        }
コード例 #12
0
        public async Task Expect_Delete_Article_With_Comments()
        {
            var createArticleCommand = new Create.Command
            {
                Article = new Create.ArticleData
                {
                    Title       = "Test article 666",
                    Description = "Description of the test article",
                    Body        = "Body of the test article"
                }
            };

            var createdArticle = await ArticleHelpers.CreateArticle(this, createArticleCommand);

            var article = await ExecuteDbContextAsync(context => context.Articles
                                                      .Include(a => a.ArticleTags)
                                                      .Where(d => d.Slug == createdArticle.Slug)
                                                      .SingleOrDefaultAsync());

            var articleId = article.ArticleId;
            var slug      = article.Slug;

            var createCommentCommand = new beeforum.Features.Comments.Create.Command
            {
                Comment = new beeforum.Features.Comments.Create.CommentData
                {
                    Body = "article comment"
                },
                Slug = slug
            };

            var comment = await CommentHelpers.CreateComment(this, createCommentCommand, UserHelpers.DefaultUserName);

            // delete article with comment
            var deleteCommand = new Delete.Command(slug);

            var dbContext = GetDbContext();

            var handler = new Delete.Handler(dbContext);
            await handler.Handle(deleteCommand, new CancellationToken());

            var deleted = await ExecuteDbContextAsync(context =>
                                                      context.Articles.Where(d => d.Slug == deleteCommand.Slug).SingleOrDefaultAsync());

            Assert.Null(deleted);
        }
コード例 #13
0
        public void Should_Delete_Technologist()
        {
            var context    = GetDbContext();
            var modalityId = Guid.NewGuid();

            context.Modalities.Add(new Domain.Modality {
                Id = modalityId, Name = "Test Modality", DisplayName = "TM"
            });
            context.SaveChanges();

            var technologistId1 = Guid.NewGuid();
            var technologistId2 = Guid.NewGuid();

            context.Technologists.Add(new Domain.Technologist
            {
                Id         = technologistId1,
                Name       = "Technologist 1",
                ModalityId = modalityId,
                Initial    = "T1"
            });


            context.Technologists.Add(new Domain.Technologist
            {
                Id         = technologistId2,
                Name       = "Technologist 2",
                ModalityId = modalityId,
                Initial    = "T2"
            });

            context.SaveChanges();

            var sut = new Delete.Handler(context);

            var result = sut.Handle(new Delete.Command {
                Id = technologistId1
            }, CancellationToken.None).Result;

            var technologists = context.Technologists.ToList();

            Assert.Single(technologists);
            Assert.Equal("Technologist 2", technologists[0].Name);
        }
コード例 #14
0
        public void Should_Delete_Room()
        {
            var context = GetDbContext();

            var locationId = Guid.NewGuid();

            var location = new Location
            {
                Id   = locationId,
                Name = "LocationForDeleteRoomTest"
            };

            context.Locations.Add(location);
            context.SaveChanges();

            var roomId1 = Guid.NewGuid();
            var roomId2 = Guid.NewGuid();

            context.Rooms.Add(new Room {
                Id = roomId1, Name = "Room 1", LocationId = locationId
            });
            context.Rooms.Add(new Room {
                Id = roomId2, Name = "Room 2", LocationId = locationId
            });

            context.SaveChanges();

            var sut = new Delete.Handler(context);

            var result = sut.Handle(new Delete.Command {
                Id = roomId1
            }, CancellationToken.None).Result;

            var room = context.Rooms.Where(x => x.LocationId == locationId).ToList();

            Assert.Single(room);
            Assert.Equal("Room 2", room[0].Name);
        }
コード例 #15
0
        public void Should_Fail_Delete_Modality_W_Invalid_Id()
        {
            var context = GetDbContext();

            context.Modalities.Add(new Domain.Modality {
                Id = Guid.NewGuid(), Name = "Test Modality"
            });
            context.SaveChanges();


            var sut = new Delete.Handler(context);

            var nonExistingModalityId = Guid.NewGuid();

            var ex = Assert.ThrowsAsync <RestException>(() => sut.Handle(new Delete.Command {
                Id = nonExistingModalityId
            }, CancellationToken.None));

            var thrownError   = ex.Result.Errors.ToString();
            var expectedError = (new { modality = "Modality Not Found" }).ToString();

            Assert.Equal(expectedError, thrownError);
        }
コード例 #16
0
 public void Setup()
 {
     _arpaContext = Substitute.For <IArpaContext>();
     _handler     = new Delete.Handler <Appointment>(_arpaContext);
 }
コード例 #17
0
 public void Setup()
 {
     _userManager = new FakeUserManager();
     _handler     = new Delete.Handler(_userManager);
 }