public async Task HandleAsync_WithCorrectCommand_ShouldReturnWebsite() { // Arrange var websiteId = Guid.NewGuid(); SeedWebsite(websiteId); IServiceScope scope = CreateScope(); var handler = scope.ServiceProvider.GetService <IRequestHandler <GetWebsite, OperationResult <WebsiteOutputModel> > >(); // Act var request = new GetWebsite(websiteId); var getWebsiteOperation = await handler.Handle(request, CancellationToken.None); // Assert getWebsiteOperation.IsSuccessful.Should().BeTrue(); getWebsiteOperation.Errors.Should().BeNull(); getWebsiteOperation.Should().BeOfType(typeof(OperationResult <WebsiteOutputModel>)); WebsiteOutputModel actualWebsite = getWebsiteOperation.Result; actualWebsite.Name.Should().Be("myWebsite"); actualWebsite.Url.Should().Be("www.mysite.com"); actualWebsite.Categories.Count.Should().Be(2); actualWebsite.Categories[0].Should().Be("category 1"); actualWebsite.Categories[1].Should().Be("category 2"); actualWebsite.Image.Name.Should().Be("myImage.png"); actualWebsite.Login.Email.Should().Be("*****@*****.**"); actualWebsite.Login.Password.Should().Be("123456"); }
public async Task HandleAsync_WithCorrectCommand_ShouldUpdateWebsites() { // Arrange SeedWebsites(); IServiceScope scope = CreateScope(); var handler = scope.ServiceProvider.GetService <IRequestHandler <GetWebsites, OperationResult <List <WebsiteOutputModel> > > >(); // Act var request = new GetWebsites { PageNumber = 1, PageSize = 3, OrderBy = string.Empty }; var getWebsitesOperation = await handler.Handle(request, CancellationToken.None); // Assert getWebsitesOperation.Result.Count.Should().Be(2); getWebsitesOperation.IsSuccessful.Should().BeTrue(); getWebsitesOperation.Errors.Should().BeNull(); getWebsitesOperation.Should().BeOfType(typeof(OperationResult <List <WebsiteOutputModel> >)); WebsiteOutputModel actualWebsite = getWebsitesOperation.Result.SingleOrDefault(w => w.Url == "www.mysite.com"); actualWebsite.Name.Should().Be("myWebsite"); actualWebsite.Url.Should().Be("www.mysite.com"); actualWebsite.Categories.Count.Should().Be(2); actualWebsite.Categories[0].Should().Be("category 1"); actualWebsite.Categories[1].Should().Be("category 2"); actualWebsite.Image.Name.Should().Be("myImage.png"); actualWebsite.Login.Email.Should().Be("*****@*****.**"); actualWebsite.Login.Password.Should().Be("123456"); WebsiteOutputModel actualWebsite1 = getWebsitesOperation.Result.SingleOrDefault(w => w.Url == "www.mysite1.com"); actualWebsite1.Name.Should().Be("myWebsite1"); actualWebsite1.Url.Should().Be("www.mysite1.com"); actualWebsite1.Categories.Count.Should().Be(2); actualWebsite1.Categories[0].Should().Be("category 11"); actualWebsite1.Categories[1].Should().Be("category 21"); actualWebsite1.Image.Name.Should().Be("myImage1.png"); actualWebsite1.Login.Email.Should().Be("*****@*****.**"); actualWebsite1.Login.Password.Should().Be("123456"); }