コード例 #1
0
        public void CreateEnterpriseTest()
        {
            var model      = new EnterpriseModel(context);
            var enterprise = model.CreateEnterprise("Fantasia", "123456000132");

            Assert.True(enterprise.Id != 0, "Falha ao inserir uma nova empresa");
        }
コード例 #2
0
        public void CannotCreateEnterpriseWithoutCNPJTest()
        {
            var model = new EnterpriseModel(context);

            Assert.Throws <BusinessException>(() =>
            {
                model.CreateEnterprise("teste", "");
            });

            Assert.Throws <BusinessException>(() =>
            {
                model.CreateEnterprise("teste", " ");
            });

            Assert.Throws <BusinessException>(() =>
            {
                model.CreateEnterprise("teste", null);
            });
        }
コード例 #3
0
        public void CannotCreateEnterpriseWithoutNameTest()
        {
            var model = new EnterpriseModel(context);

            Assert.Throws <BusinessException>(() =>
            {
                model.CreateEnterprise("", "123123213213");
            });

            Assert.Throws <BusinessException>(() =>
            {
                model.CreateEnterprise(" ", "123123213213");
            });

            Assert.Throws <BusinessException>(() =>
            {
                model.CreateEnterprise(null, "123123213213");
            });
        }
コード例 #4
0
        public string Post()
        {
            var content = Body;
            var account = JsonConvert.DeserializeObject <AccountTO>(content);

            try
            {
                var person = personModel.CreatePerson(account.Name, account.LastName, account.CPF, account.Email, account.Phone);
                enterpriseModel.CreateEnterprise(account.Enterprise.Name, account.Enterprise.Cnpj);
                userModel.CreateUser(person.Id, account.User.Username, account.User.Password);
                return(JsonConvert.SerializeObject(new ResponseTO()
                {
                    Code = 200,
                    Message = "Conta cadastrada com sucesso.",
                    Data = person.Id
                }));
            }
            catch (BusinessException be)
            {
                return(JsonConvert.SerializeObject(new ResponseTO()
                {
                    Code = 500,
                    Message = be.Message
                }));
            }
            catch (ArgumentException ae)
            {
                return(JsonConvert.SerializeObject(new ResponseTO()
                {
                    Code = 500,
                    Message = ae.Message
                }));
            }
            catch (Exception)
            {
                return(JsonConvert.SerializeObject(new ResponseTO()
                {
                    Code = 500,
                    Message = "Erro desconhecido. Tente novamente mais tarde."
                }));
            }
        }