public void ShouldNotCallHandleIfNotSavedChanges() { context.Setup(x => x.AdditionalInfoDefinitions).Returns(dbSetAdditionalInfoDefinition.Object); context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(0)); CreateAdditionalInfoDefinitionCommandHandler createAdditionalInfoDefinitionCommandHandler = new CreateAdditionalInfoDefinitionCommandHandler(context.Object, stringLocalizer.Object, mapper.Object); CreateAdditionalInfoDefinitionCommand createAdditionalInfoDefinitionCommand = new CreateAdditionalInfoDefinitionCommand(); mapper.Setup(x => x.Map <AdditionalInfoDefinition>(createAdditionalInfoDefinitionCommand)).Returns(new AdditionalInfoDefinition()); Func <Task> act = async() => await createAdditionalInfoDefinitionCommandHandler.Handle(createAdditionalInfoDefinitionCommand, new CancellationToken()); act.Should().ThrowAsync <RestException>(); }
public async Task ShouldRequireFieldAndThrowValidationExceptionDuringArticleCreating(string infoName, TypeOfField typeOfField) { var loggedUser = await RunAsUserAsync("scott101@localhost", "Pa$$w0rd!"); var additionalInfoDefinitionToCreate = new Faker <AdditionalInfoDefinitionCreateOrEditDto>("en") .RuleFor(a => a.Id, f => f.Random.Guid()) .RuleFor(a => a.InfoName, f => infoName) .RuleFor(a => a.TypeOfField, f => typeOfField) .Generate(); var command = new CreateAdditionalInfoDefinitionCommand(additionalInfoDefinitionToCreate); Func <Task> act = async() => await SendAsync(command); act.Should().Throw <Common.Exceptions.ValidationException>(); }
public async Task ShouldCallHandle() { var id = new Guid(); var additionalInfoDefinitionDto = new AdditionalInfoDefinitionCreateOrEditDto { Id = id }; var additionalInfoDefinition = new AdditionalInfoDefinition { Id = id }; context.Setup(x => x.AdditionalInfoDefinitions).Returns(dbSetAdditionalInfoDefinition.Object); context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(1)); CreateAdditionalInfoDefinitionCommandHandler createAdditionalInfoDefinitionCommandHandler = new CreateAdditionalInfoDefinitionCommandHandler(context.Object, stringLocalizer.Object, mapper.Object); CreateAdditionalInfoDefinitionCommand createAdditionalInfoDefinitionCommand = new CreateAdditionalInfoDefinitionCommand(additionalInfoDefinitionDto); mapper.Setup(x => x.Map <AdditionalInfoDefinition>(createAdditionalInfoDefinitionCommand)).Returns(additionalInfoDefinition); var result = await createAdditionalInfoDefinitionCommandHandler.Handle(createAdditionalInfoDefinitionCommand, new CancellationToken()); result.Should().Be(id); }
public async Task ShouldCreateAdditionalInfoDefinition() { var loggedUser = await RunAsUserAsync("scott101@localhost", "Pa$$w0rd!"); var additionalInfoDefinitionToCreate = new Faker <AdditionalInfoDefinitionCreateOrEditDto>("en") .RuleFor(a => a.Id, f => f.Random.Guid()) .RuleFor(a => a.InfoName, f => f.Lorem.Word()) .RuleFor(a => a.TypeOfField, f => TypeOfField.Text) .Generate(); var command = new CreateAdditionalInfoDefinitionCommand(additionalInfoDefinitionToCreate); var additionalInfoDefinitionId = await SendAsync(command); var createdAdditionalInfoDefinition = await FindByGuidAsync <AdditionalInfoDefinition>(additionalInfoDefinitionId); createdAdditionalInfoDefinition.Id.Should().Be(additionalInfoDefinitionId); createdAdditionalInfoDefinition.InfoType.Should().Be("string"); createdAdditionalInfoDefinition.InfoName.Should().Be(additionalInfoDefinitionToCreate.InfoName); createdAdditionalInfoDefinition.CreatedBy.Should().Be(loggedUser); createdAdditionalInfoDefinition.Created.Should().BeCloseTo(DateTime.UtcNow, 1000); }