Beispiel #1
0
        public void ATestPostArticolo()
        {
            // Arrange
            var dbContext  = DbContextMocker.nanshopDbContext();
            var controller = new ArticoliController(new ArticoliStore(dbContext), MapperMocker.GetMapper());

            // Act
            var response = controller.PostArticolo(this.CreateArtTest()) as ObjectResult;
            var value    = response.Value as InfoMsg;

            dbContext.Dispose();

            // Assert
            Assert.Equal(200, response.StatusCode);
            Assert.NotNull(value);
            Assert.Equal("Inserimento articolo 124ProvaIns eseguita con successo!", value.Message);
        }
Beispiel #2
0
        public void BTestPostArticoloKO()
        {
            // Arrange
            var dbContext  = DbContextMocker.nanshopDbContext();
            var controller = new ArticoliController(new ArticoliStore(dbContext), MapperMocker.GetMapper());

            // Act
            var response = controller.PostArticolo(this.CreateArtTest()) as ObjectResult;
            var value    = response.Value as InfoMsg;

            dbContext.Dispose();

            // Assert
            Assert.Equal(422, response.StatusCode);
            Assert.NotNull(value);
            Assert.Equal("Articolo 124ProvaIns presente in anagrafica! Impossibile utilizzare il metodo POST!", value.Message);
        }
Beispiel #3
0
        public void DTestDeleteArticolo()
        {
            // Arrange
            var dbContext  = DbContextMocker.nanshopDbContext();
            var controller = new ArticoliController(new ArticoliStore(dbContext), MapperMocker.GetMapper());

            // Act
            var response = controller.DeleteArticolo("124ProvaIns") as ObjectResult;
            var value    = response.Value as InfoMsg;

            dbContext.Dispose();

            // Assert
            Assert.Equal(200, response.StatusCode);
            Assert.NotNull(value);
            Assert.Equal("Eliminazione articolo 124ProvaIns eseguita con successo!", value.Message);
        }
        public async Task TestErrSelArticoliByDescrizione()
        {
            string Descrizione = "Pippo";

            // Arrange
            var dbContext  = DbContextMocker.nanshopDbContext();
            var controller = new ArticoliController(new ArticoliStore(dbContext), MapperMocker.GetMapper());

            // Act
            var actionResult = await controller.GetArticoliByDesc(Descrizione, "");

            dbContext.Dispose();

            var result = actionResult.Result as ObjectResult;
            var value  = result.Value as ICollection <ArticoliDTO>;

            Assert.Equal(404, result.StatusCode);
            Assert.Null(value);
            Assert.Equal("Non è stato trovato alcun articolo con il filtro 'Pippo'", result.Value);
        }
        public async Task TestErrGetArticoloByCode()
        {
            string CodArt = "0009926010";

            // Arrange
            var dbContext  = DbContextMocker.nanshopDbContext();
            var controller = new ArticoliController(new ArticoliStore(dbContext), MapperMocker.GetMapper());

            // Act
            var response = await controller.GetArticoloByCodice(CodArt) as ObjectResult;

            var value = response.Value as ArticoliDTO;

            dbContext.Dispose();

            // Assert
            Assert.Equal(404, response.StatusCode);
            Assert.Null(value);
            Assert.Equal("Non è stato trovato l'articolo con codice '0009926010'", response.Value);
        }
        public async Task TestGetArticoloByCodice()
        {
            string codArt = "000992601";

            //arrange
            var dbContext  = DbContextMocker.nanshopDbContext();
            var controller = new ArticoliController(new ArticoliStore(dbContext), MapperMocker.GetMapper());

            // Act
            var response = await controller.GetArticoloByCodice(codArt) as ObjectResult;

            var value = response.Value as ArticoliDTO;

            dbContext.Dispose();

            // Assert
            Assert.Equal(200, response.StatusCode);
            Assert.NotNull(value);
            Assert.Equal(codArt, value.CodArt);
        }
        public async Task TestErrSelArticoloByEan()
        {
            string Ean = "80582533A";

            // Arrange
            var dbContext  = DbContextMocker.nanshopDbContext();
            var controller = new ArticoliController(new ArticoliStore(dbContext), MapperMocker.GetMapper());

            // Act
            var response = await controller.GetArticoloByEan(Ean) as ObjectResult;

            var value = response.Value as ArticoliDTO;

            dbContext.Dispose();

            // Assert
            Assert.Equal(404, response.StatusCode);
            Assert.Null(value);
            Assert.Equal("Non è stato trovato l'articolo con ean '80582533A'", response.Value);
        }
        public async Task TestSelArticoloByEan()
        { // System.InvalidCastException : Unable to cast object of type 'System.Int16' to type 'System.Int32'.
            string Ean = "80582533";

            // Arrange
            var dbContext  = DbContextMocker.nanshopDbContext();
            var controller = new ArticoliController(new ArticoliStore(dbContext), MapperMocker.GetMapper());

            // Act
            var response = await controller.GetArticoloByEan(Ean) as ObjectResult;

            var value = response.Value as ArticoliDTO;

            dbContext.Dispose();

            // Assert
            Assert.Equal(200, response.StatusCode);
            Assert.NotNull(value);
            Assert.Equal("000974302", value.CodArt);
        }
        public async Task TestSelArticoliByDescrizione()
        { // System.NullReferenceException : Object reference not set to an instance of an object.
            string Descrizione = "ACQUA ROCCHETTA";

            // Arrange
            var dbContext  = DbContextMocker.nanshopDbContext();
            var controller = new ArticoliController(new ArticoliStore(dbContext), MapperMocker.GetMapper());

            // Act
            var actionResult = await controller.GetArticoliByDesc(Descrizione, "");

            dbContext.Dispose();

            var result = actionResult.Result as ObjectResult;
            var value  = result.Value as ICollection <ArticoliDTO>;



            // Assert
            Assert.Equal(200, result.StatusCode);
            Assert.NotNull(value);
            Assert.Equal(3, value.Count);
            Assert.Equal("002001201", value.FirstOrDefault().CodArt);
        }