Exemplo n.º 1
0
        public Company MapToEntity(Domain.Company dComp)
        {
            var company = new Company();

            MapToEntity(ref company, dComp);
            return(company);
        }
Exemplo n.º 2
0
        public void SaveCompanyTestCase()
        {
            var targetCompany = new Domain.Company
            {
                Excluded          = false,
                LegalPersonDetail = new Domain.SubEntity.LegalPersonDetail
                {
                    Cnpj = new Domain.SubEntity.Cnpj
                    {
                        CheckNumber = 12,
                        Root        = 12345,
                        Suffix      = 12
                    },
                    CompanyName = "Bad Cat Corporation S/A",
                    TradingName = "BadCat SA",
                    IE          = 123456
                }
            };

            CompanyDao.Save(targetCompany);

            ResultInspector.AreEqual(ResultInspector.GetExpectedTable(
                                         "Schemas.ErpSchema.xsd",
                                         "Dataset.InsertedCompany.xml",
                                         "tb_company"
                                         ),
                                     GetCompanies()
                                     );
        }
Exemplo n.º 3
0
        public void SaveCompanyTestCase()
        {
            var targetCompany = new Domain.Company
                                    {
                                        Excluded = false,
                                        LegalPersonDetail = new Domain.SubEntity.LegalPersonDetail
                                                                {
                                                                    Cnpj = new Domain.SubEntity.Cnpj
                                                                               {
                                                                                   CheckNumber = 12,
                                                                                   Root = 12345,
                                                                                   Suffix = 12
                                                                               },
                                                                    CompanyName = "Bad Cat Corporation S/A",
                                                                    TradingName = "BadCat SA",
                                                                    IE = 123456
                                                                }
                                    };
            CompanyDao.Save(targetCompany);

            ResultInspector.AreEqual(ResultInspector.GetExpectedTable(
                "Schemas.ErpSchema.xsd",
                "Dataset.InsertedCompany.xml",
                "tb_company"
                                         ),
                                     GetCompanies()
                );
        }
Exemplo n.º 4
0
        public async Task DisconnectMovie_ValidInput_ReturnsTrue(int id, int movieID, int expectedID)
        {
            #region Arrange
            var dbContext = new ApplicationDbContext(_dbContextOptions);
            await dbContext.Database.EnsureDeletedAsync();

            var company = new Domain.Company();
            dbContext.Companies.Add(company);

            var movie = new Domain.Movie();
            dbContext.Movies.Add(movie);

            var companyMovie = new Domain.CompanyMovie
            {
                CompanyID = company.ID,
                MovieID   = movie.ID
            };
            dbContext.CompanyMovies.Add(companyMovie);

            await dbContext.SaveChangesAsync();

            var appCompany = new Company(dbContext);
            #endregion

            #region Act
            var actual = await appCompany.DisconnectMovie(new AdminCompanyMovieModel { CompanyID = id, MovieID = movieID });

            #endregion

            #region Assert
            Assert.NotNull(actual);
            Assert.Equal(expectedID, actual.ID);
            #endregion
        }
Exemplo n.º 5
0
        public async Task Update_InvalidInput_ReturnsNull(int id, string name, CompanyTypes companyType)
        {
            #region Arrange
            var dbContext = new ApplicationDbContext(_dbContextOptions);
            await dbContext.Database.EnsureDeletedAsync();

            var company = new Domain.Company
            {
                Name = "Name",
                Type = CompanyTypes.Producer
            };
            dbContext.Companies.Add(company);

            await dbContext.SaveChangesAsync();

            var newCompany = new AdminCompanyModel
            {
                ID   = id,
                Name = name,
                Type = companyType
            };

            var appCompany = new Company(dbContext);
            #endregion

            #region Act
            var actualCompany = await appCompany.Update(newCompany);

            #endregion

            #region Assert
            Assert.Null(actualCompany);
            #endregion
        }
        public async Task DisconnectMovie_ValidRequest_ReturnsJsonResponseAndOk(int id, int movieID)
        {
            #region Arrange
            await DeleteDbContent();

            var client    = GetHttpClient();
            var dbContext = GetDbContext();

            var company = new Domain.Company();
            dbContext.Companies.Add(company);

            var movie = new Domain.Movie();
            dbContext.Movies.Add(movie);
            await dbContext.SaveChangesAsync();

            dbContext.CompanyMovies.Add(new Domain.CompanyMovie
            {
                CompanyID = company.ID,
                MovieID   = movie.ID
            });
            await dbContext.SaveChangesAsync();

            #endregion

            #region Act
            var response = await client.DeleteAsync($"/api/company/{id}/movies/{movieID}");

            #endregion

            #region Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            #endregion
        }
Exemplo n.º 7
0
        public Task Add(Domain.Company dComp)
        {
            var company = mapper.MapToEntity(dComp);

            store.Companies.Add(company);
            return(store.SaveChangesAsync());
        }
Exemplo n.º 8
0
        public async Task Update(Domain.Company dComp)
        {
            var company = await IncludeAll(store.Companies)
                          .SingleOrDefaultAsync(c => c.CompanyId == dComp.CompanyId);

            mapper.MapToEntity(ref company, dComp);
            await store.SaveChangesAsync();
        }
Exemplo n.º 9
0
 public void MapToEntity(ref Company company, Domain.Company dComp)
 {
     company.CompanyId = dComp.CompanyId;
     company.Name      = dComp.Name;
     // company.CompanySize = MapCompanySize(dComp.CompanySize);
     company.CompanySizeId = dComp.CompanySize.CompanySizeId;
     company.Offices       = dComp.Offices.Select(dLoc => MapOfficeToEntity(dLoc, dComp.CompanyId)).ToHashSet();
 }
Exemplo n.º 10
0
        public Domain.Company MapFromEntity(Company company)
        {
            var dComp = new Domain.Company();

            dComp.CompanyId   = company.CompanyId;
            dComp.Name        = company.Name;
            dComp.CompanySize = MapCompanySize(company.CompanySize);
            dComp.Offices     = company.Offices.Select(cl => MapOfficeFromEntity(cl)).ToList();
            return(dComp);
        }
Exemplo n.º 11
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            Domain.Company company = Domain.SqlDataFlow.FindCompanyById(id);

            if (company == null)
            {
                return(HttpNotFound());
            }
            return(View(company));
        }
Exemplo n.º 12
0
        public Domain.Company MockCompany(string companyName, Domain.Address address)
        {
            var company = new Domain.Company(new Domain.Errors());

            company.CompanySize = new Domain.CompanySize {
                CompanySizeId = 1
            };
            company.CompanyId = Guid.NewGuid();
            company.Name      = "FDHSMV";
            var office = new Domain.Office();

            office.OfficeId = Guid.NewGuid();
            office.Address  = address;
            company.Offices = new List <Domain.Office> {
                office
            };
            return(company);
        }
Exemplo n.º 13
0
        public ActionResult DeleteConfirmed(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            Domain.Company company = Domain.SqlDataFlow.FindCompanyById(id);

            if (company == null)
            {
                return(HttpNotFound());
            }

            Domain.SqlDataFlow.DeleteCompany(company);

            return(RedirectToAction("CompaniesList"));
        }
        public void SeedCompany()
        {
            var company = new Domain.Company()
            {
                Code             = "VietPower",
                Name             = "Công Ty TNHH Sản Xuất Tủ Bảng Điện VietPower",
                Address          = "KM1855 Đường Võ Nguyên Giáp (Quốc Lộ 1A), Xã Phước Tân, Thành Phố Biên Hòa, Tỉnh Đồng Nai",
                Phone            = "(84-61) 2860669 / 2860779",
                PhoneBackup      = "",
                CompanyAccountId = 1,
                CreatedAt        = new DateTime(),
                UpdatedAt        = new DateTime(),
                CreatedBy        = 1,
                UpdatedBy        = 1
            };

            _databaseService.Companies.Add(company);
        }
        public async Task DisconnectMovie_InvalidRequest_ReturnsJsonResponseAndNotFoundWithErrors(int id, int movieID, IEnumerable <string> expectedErrorNames, IEnumerable <string> expectedErrorMessages)
        {
            #region Arrange
            await DeleteDbContent();

            var client    = GetHttpClient();
            var dbContext = GetDbContext();

            var company = new Domain.Company();
            dbContext.Companies.Add(company);

            var movie = new Domain.Movie();
            dbContext.Movies.Add(movie);

            if (id != 1 && movieID != 1)
            {
                dbContext.CompanyMovies.Add(new Domain.CompanyMovie
                {
                    CompanyID = company.ID,
                    MovieID   = movie.ID
                });
            }
            await dbContext.SaveChangesAsync();

            #endregion

            #region Act
            var response = await client.DeleteAsync($"/api/company/{id}/movies/{movieID}");

            var responseBody = await response.Content.ReadAsStreamAsync();

            var actualCompany = await JsonSerializer.DeserializeAsync <JsonElement>(responseBody);

            var errorProp = actualCompany.GetProperty("errors");
            var errors    = errorProp.EnumerateObject();
            #endregion

            #region Assert
            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
            Assert.Equal(expectedErrorNames.Count(), errors.Count());
            Assert.All(expectedErrorNames, errorName => Assert.Contains(errorName, errors.Select(prop => prop.Name)));
            Assert.All(expectedErrorMessages, errorMessage => Assert.Contains(errorMessage, errors.Select(prop => prop.Value[0].ToString())));
            #endregion
        }
Exemplo n.º 16
0
        public Domain.Company MockCompany(string companyName)
        {
            var company = new Domain.Company(new Domain.Errors());

            company.CompanySize = new Domain.CompanySize {
                CompanySizeId = 1
            };
            company.CompanyId = Guid.NewGuid();
            company.Name      = companyName;
            var office = new Domain.Office();

            office.OfficeId = Guid.NewGuid();
            office.Address  = new Domain.Address {
                AddressId = Guid.NewGuid(), StreetNumber = "1112", StreetAddress = "Carissa Dr.", City = "TTown", State = "FL", ZipCode = "32308"
            };
            company.Offices = new List <Domain.Office> {
                office
            };
            return(company);
        }
        public async Task Read_ValidRequest_ReturnsJsonResponseAndOk(int id)
        {
            #region Arrange
            await DeleteDbContent();

            var client    = GetHttpClient();
            var dbContext = GetDbContext();

            var company = new Domain.Company
            {
                Name = "Name",
                Type = CompanyTypes.Producer
            };
            dbContext.Companies.Add(company);
            await dbContext.SaveChangesAsync();

            var expectedCompany = new CompanyModel
            {
                ID   = company.ID,
                Name = company.Name,
                Type = company.Type.ToString()
            };
            #endregion

            #region Act
            var response = await client.GetAsync($"/api/company/{id}");

            var responseBody = await response.Content.ReadAsStreamAsync();

            var actualCompany = await JsonSerializer.DeserializeAsync <CompanyModel>(responseBody);

            #endregion

            #region Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(expectedCompany.ID, actualCompany.ID);
            Assert.Equal(expectedCompany.Name, actualCompany.Name);
            Assert.Equal(expectedCompany.Type, actualCompany.Type);
            #endregion
        }
Exemplo n.º 18
0
        public async Task Read_ValidInput_ReturnsCorrectData(int id)
        {
            #region Arrange
            var dbContext = new ApplicationDbContext(_dbContextOptions);
            await dbContext.Database.EnsureDeletedAsync();

            var company = new Domain.Company
            {
                ID   = id,
                Name = "Name",
                Type = CompanyTypes.Distributor
            };
            dbContext.Companies.Add(company);
            await dbContext.SaveChangesAsync();

            var expectedCompany = new CompanyModel
            {
                ID   = id,
                Name = company.Name,
                Type = company.Type.ToString()
            };

            var appCompany = new Company(dbContext);
            #endregion

            #region Act
            var actualCompany = await appCompany.Read(id);

            #endregion

            #region Assert
            Assert.Equal(expectedCompany.ID, actualCompany.ID);
            Assert.Equal(expectedCompany.Name, actualCompany.Name);
            Assert.Equal(expectedCompany.Type, actualCompany.Type);
            #endregion
        }
Exemplo n.º 19
0
 public ActionResult Edit(Domain.Company company)
 {
     Domain.SqlDataFlow.UpdateCompany(company);
     return(RedirectToAction("CompaniesList"));
 }
Exemplo n.º 20
0
        public ActionResult Create(Domain.Company company)
        {
            Domain.SqlDataFlow.AddCompany(company);

            return(RedirectToAction("CompaniesList"));
        }