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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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;
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
 public BuyBeersUseCase(IBeerCatalog catalog)
 {
     _catalog = catalog;
 }
Exemplo n.º 10
0
 public AddBeerUseCase(IBeerCatalog catalog)
 {
     _catalog = catalog;
 }
Exemplo n.º 11
0
 public UpdateBeerUseCase(IBeerCatalog catalog)
 {
     _catalog = catalog;
 }
Exemplo n.º 12
0
 public GetOneBeerUseCase(IBeerCatalog catalog)
 {
     _catalog = catalog;
 }
 public CheckBeersAvailabilityUseCase(IBeerCatalog catalog)
 {
     _catalog = catalog;
 }
Exemplo n.º 14
0
 public CreateNewBeer(IBeerCatalog catalog)
 {
     _catalog = catalog;
 }
Exemplo n.º 15
0
 public DeleteBeerUseCase(IBeerCatalog catalog)
 {
     _catalog = catalog;
 }
Exemplo n.º 16
0
 public DeleteExistingBeer(IBeerCatalog catalog)
 {
     _catalog = catalog;
 }
Exemplo n.º 17
0
 public GetAllBeers(IBeerCatalog catalog)
 {
     _catalog = catalog;
 }
Exemplo n.º 18
0
 public ApiBeerController(IBeerCatalog catalog)
 {
     _catalog = catalog;
 }
Exemplo n.º 19
0
 public GetOneBeer(IBeerCatalog catalog)
 {
     _catalog = catalog;
 }
Exemplo n.º 20
0
 public GetAllBeersUseCase(IBeerCatalog catalog)
 {
     _catalog = catalog;
 }
Exemplo n.º 21
0
 public UpdateExistingBeer(IBeerCatalog catalog)
 {
     _catalog = catalog;
 }