Exemplo n.º 1
0
        public async Task ShouldNotSigninWithWrongPassword()
        {
            var server    = new ServerFake();
            var user      = server.AppDbContext.CreateUser();
            var viewModel = UserFactory.SigninViewModel(user, password: "******");
            var response  = await server.CreateClient().PostAsJsonAsync("signin", viewModel);

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
Exemplo n.º 2
0
        public async Task ShouldSignin()
        {
            var server    = new ServerFake();
            var user      = server.AppDbContext.CreateUser();
            var viewModel = UserFactory.SigninViewModel(user);
            var response  = await server.CreateClient().PostAsJsonAsync("signin", viewModel);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
Exemplo n.º 3
0
        public async Task ShouldSignout()
        {
            var server   = new ServerFake();
            var user     = server.AppDbContext.CreateUser();
            var response = await server.CreateAuthenticatedClient(user).GetAsync("signout");

            Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
            Assert.Equal("/signin", response.Headers.Location.ToString());
        }
Exemplo n.º 4
0
        public async Task ShouldDelete()
        {
            var server    = new ServerFake();
            var user      = server.AppDbContext.CreateUser();
            var product   = server.AppDbContext.CreateProduct(user.Tenant);
            var viewModel = new ProductIdViewModel().For(product);
            var response  = await server.CreateAuthenticatedClient(user).PostAsJsonAsync("products/delete", viewModel);

            var json = await response.Content.ReadAsJsonAsync <ProductJson>();

            Assert.True(response.IsSuccessStatusCode);
            Assert.False(server.AppDbContext.Products.WhereId(json.Id).Any());
        }
Exemplo n.º 5
0
        public async Task ShouldSignup()
        {
            var server    = new ServerFake();
            var user      = server.AppDbContext.BuildUser();
            var viewModel = new SignupViewModel {
                Name = user.Name, Email = user.Email, Password = user.Password
            };
            var response = await server.CreateClient().PostAsJsonAsync("signup", viewModel);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.True(server.AppDbContext.Users.WhereEmail(user.Email).Any());
            Assert.True(server.AppDbContext.ClosureRequests.WhereEmail(user.Email).Any());
            Assert.True(server.Mailer.EmailSent);
        }
Exemplo n.º 6
0
        public async Task ShouldList()
        {
            var server         = new ServerFake();
            var user           = server.AppDbContext.CreateUser();
            var product        = server.AppDbContext.CreateProduct(user.Tenant);
            var anotherProduct = server.AppDbContext.CreateProduct(user.Tenant);
            var viewModel      = new ListProductsViewModel();
            var response       = await server.CreateAuthenticatedClient(user).PostAsJsonAsync("products/list", viewModel);

            var json = await response.Content.ReadAsJsonAsync <ProductListJson>();

            Assert.True(response.IsSuccessStatusCode);
            Assert.Equal(2, json.Products.Count);
        }
Exemplo n.º 7
0
        public async Task ShouldNotCreateWithoutRequiredFields()
        {
            var server    = new ServerFake();
            var user      = server.AppDbContext.CreateUser();
            var viewModel = new CreateProductViewModel();
            var response  = await server.CreateAuthenticatedClient(user).PostAsJsonAsync("products/create", viewModel);

            var json = await response.Content.ReadAsJsonAsync <ErrorsJson>();

            var errors = new[] { "Name: Required", "InventoryControl: Required" };

            Assert.Equal((HttpStatusCode)422, response.StatusCode);
            Assert.Equal(json.Errors.OrderBy(e => e), errors.OrderBy(e => e));
        }
Exemplo n.º 8
0
        public async Task ShouldListByInventoryControl()
        {
            var server         = new ServerFake();
            var user           = server.AppDbContext.CreateUser();
            var product        = server.AppDbContext.CreateProduct(user.Tenant, inventoryControl: InventoryControl.Unit);
            var anotherProduct = server.AppDbContext.CreateProduct(user.Tenant, inventoryControl: InventoryControl.None);
            var viewModel      = new ListProductsViewModel().Where(inventoryControl: product.InventoryControl);
            var response       = await server.CreateAuthenticatedClient(user).PostAsJsonAsync("products/list", viewModel);

            var json = await response.Content.ReadAsJsonAsync <ProductListJson>();

            Assert.True(response.IsSuccessStatusCode);
            Assert.True(json.Products.Where(productJson => productJson.Id == product.Id).Any());
            Assert.Equal(1, json.Products.Count);
        }
Exemplo n.º 9
0
        public async Task ShouldNotSigninWithoutRequiredFields()
        {
            var server   = new ServerFake();
            var response = await server.CreateClient().PostAsJsonAsync("signin");

            var errors = await response.Content.ReadAsJsonAsync <List <string> >();

            var expectedErrors = new []
            {
                "The Email field is required.",
                "The Password field is required."
            };

            Assert.Equal((HttpStatusCode)422, response.StatusCode);
            Assert.Equal(errors.OrderBy(e => e), expectedErrors.OrderBy(e => e));
        }
Exemplo n.º 10
0
        public async Task ShouldNotSignupWithEmailAlreadyTaken()
        {
            var server    = new ServerFake();
            var user      = server.AppDbContext.CreateUser();
            var viewModel = new SignupViewModel {
                Name = "Another", Email = user.Email, Password = UserFactory.Password
            };
            var response = await server.CreateClient().PostAsJsonAsync("signup", viewModel);

            var errors = await response.Content.ReadAsJsonAsync <List <string> >();

            var expectedErrors = new [] { "E-mail já cadastrado." };

            Assert.Equal((HttpStatusCode)422, response.StatusCode);
            Assert.Equal(errors.OrderBy(e => e), expectedErrors.OrderBy(e => e));
            Assert.False(server.Mailer.EmailSent);
        }
Exemplo n.º 11
0
        public async Task ShouldFind()
        {
            var server    = new ServerFake();
            var user      = server.AppDbContext.CreateUser();
            var product   = server.AppDbContext.CreateProduct(user.Tenant);
            var viewModel = new ProductIdViewModel().For(product);
            var response  = await server.CreateAuthenticatedClient(user).PostAsJsonAsync("products/find", viewModel);

            var json = await response.Content.ReadAsJsonAsync <ProductJson>();

            Assert.True(response.IsSuccessStatusCode);
            Assert.NotNull(product);
            Assert.Equal(product.Name, json.Name);
            Assert.Equal(product.Code, json.Code);
            Assert.Equal(product.Marketed, json.Marketed);
            Assert.Equal(product.IsManufactured, json.IsManufactured);
            Assert.Equal(product.CanFraction, json.CanFraction);
            Assert.Equal(product.InventoryControl, json.InventoryControl);
            Assert.Equal(product.AdditionalInformation, json.AdditionalInformation);
        }
Exemplo n.º 12
0
        public async Task ShouldCreate()
        {
            var server    = new ServerFake();
            var user      = server.AppDbContext.CreateUser();
            var viewModel = new CreateProductViewModel().Filled();
            var response  = await server.CreateAuthenticatedClient(user).PostAsJsonAsync("products/create", viewModel);

            var json = await response.Content.ReadAsJsonAsync <ProductJson>();

            var product = server.AppDbContext.Products.WhereId(json.Id).SingleOrDefault();

            Assert.True(response.IsSuccessStatusCode);
            Assert.NotNull(product);
            Assert.Equal(viewModel.Name, product.Name);
            Assert.Equal(viewModel.Code, product.Code);
            Assert.Equal(viewModel.Marketed, product.Marketed);
            Assert.Equal(viewModel.IsManufactured, product.IsManufactured);
            Assert.Equal(viewModel.CanFraction, product.CanFraction);
            Assert.Equal(viewModel.InventoryControl, product.InventoryControl);
            Assert.Equal(viewModel.AdditionalInformation, product.AdditionalInformation);
        }