public UpdateExistingBeerValidator(IBeerCatalog catalog) { RuleFor(beer => beer.Id) .Custom((id, context) => { if (catalog.FindOneBeerByGuid(id) == null) { context.AddFailure("Unknown beer."); } }) .NotNull(); RuleFor(beer => beer.Label) .NotNull() .NotEmpty() .MinimumLength(3); RuleFor(beer => beer.Description) .NotNull() .NotEmpty() .MinimumLength(3); RuleFor(beer => beer.Stock) .NotNull() .GreaterThanOrEqualTo(0); }
public UpdateBeerValidator(IBeerCatalog catalog) { RuleFor(x => x.Id) .NotNull() .NotEmpty() .Custom((id, context) => { if (catalog.GetOneBeer(id) == null) { context.AddFailure("Unknown beer."); } }); RuleFor(x => x.Label) .NotNull() .NotEmpty() .MinimumLength(3) .MaximumLength(50); RuleFor(x => x.Description) .NotNull() .NotEmpty() .MinimumLength(3) .MaximumLength(250); RuleFor(x => x.Stock) .NotNull() .GreaterThanOrEqualTo(0) .LessThanOrEqualTo(int.MaxValue); }
public AddBeerValidator(IBeerCatalog catalog) { RuleFor(x => x.Label) .NotNull() .NotEmpty() .MinimumLength(3) .MaximumLength(50) .Custom((label, context) => { if (catalog.GetAllBeers().Any(y => y.Label.Value.Equals(label))) { context.AddFailure($"The label \"{label}\" already exists."); } }); RuleFor(x => x.Description) .NotNull() .NotEmpty() .MinimumLength(3) .MaximumLength(250); RuleFor(x => x.Stock) .NotNull() .GreaterThanOrEqualTo(0) .LessThanOrEqualTo(int.MaxValue); }
public CreateNewBeerTest() { var catalogMock = new Mock <IBeerCatalog>(); catalogMock.Setup(c => c.CreateNewBeer(It.IsAny <Beer>())).Returns((Beer beer) => beer); _catalog = catalogMock.Object; }
public UpdateExistingBeerTest() { var catalogMock = new Mock <IBeerCatalog>(); catalogMock.Setup(c => c.UpdateExistingBeer(It.IsAny <Beer>())).Returns((Beer beer) => beer); catalogMock.Setup(c => c.FindOneBeerByGuid(It.IsAny <Guid>())) .Returns((Guid Id) => new Beer(null, "Label", "Description", 0)); _catalogMock = catalogMock; _catalog = catalogMock.Object; }
public GetAllBeersTest() { var catalogMock = new Mock <IBeerCatalog>(); const string beerLabel = "Sample Label"; const string beerDescription = "Sample Description"; const int beerStock = 250; catalogMock.Setup(c => c.FindAllBeers()).Returns(new List <Beer> { new Beer(null, beerLabel, beerDescription, beerStock), new Beer(null, beerLabel, beerDescription, beerStock) }.AsQueryable()); _catalog = catalogMock.Object; }
public void ItShouldNotReturnRequestedBeer() { var catalogMock = new Mock <IBeerCatalog>(); catalogMock.Setup(c => c.FindOneBeerByGuid(It.IsAny <Guid>())).Returns( (Guid Id) => null ); _catalog = catalogMock.Object; var id = Guid.NewGuid(); var request = new GetOneBeerRequest { Id = id }; var getOneBeerUseCase = new GetOneBeer(_catalog); getOneBeerUseCase.Execute(request, this); Assert.Null(Response.Beer); }
public void ItShouldReturnRequestedBeer() { var catalogMock = new Mock <IBeerCatalog>(); catalogMock.Setup(c => c.FindOneBeerByGuid(It.IsAny <Guid>())).Returns( (Guid Id) => new Beer(Id, "Sample Label", "Sample Description", 0) ); _catalog = catalogMock.Object; var id = Guid.NewGuid(); var request = new GetOneBeerRequest { Id = id }; var getOneBeerUseCase = new GetOneBeer(_catalog); getOneBeerUseCase.Execute(request, this); Assert.Equal(id, Response.Beer.Id.Value); }
public BuyBeersUseCase(IBeerCatalog catalog) { _catalog = catalog; }
public AddBeerUseCase(IBeerCatalog catalog) { _catalog = catalog; }
public UpdateBeerUseCase(IBeerCatalog catalog) { _catalog = catalog; }
public GetOneBeerUseCase(IBeerCatalog catalog) { _catalog = catalog; }
public CheckBeersAvailabilityUseCase(IBeerCatalog catalog) { _catalog = catalog; }
public CreateNewBeer(IBeerCatalog catalog) { _catalog = catalog; }
public DeleteBeerUseCase(IBeerCatalog catalog) { _catalog = catalog; }
public DeleteExistingBeer(IBeerCatalog catalog) { _catalog = catalog; }
public GetAllBeers(IBeerCatalog catalog) { _catalog = catalog; }
public ApiBeerController(IBeerCatalog catalog) { _catalog = catalog; }
public GetOneBeer(IBeerCatalog catalog) { _catalog = catalog; }
public GetAllBeersUseCase(IBeerCatalog catalog) { _catalog = catalog; }
public UpdateExistingBeer(IBeerCatalog catalog) { _catalog = catalog; }