Пример #1
0
        public void GetOrderClientCards()
        {
            var clientCardFromBody2 = new ClientCardFromBody(
                "2",
                "Антон",
                "ЕКБ",
                "8",
                "*****@*****.**",
                "TV",
                "Display",
                "Sergey",
                "123",
                new DateTime(2018, 01, 01),
                new DateTime(2018, 01, 01),
                new string[] { "sr" },
                new string[][] { new string[] { "resistor1", "10" }, new string[] { "resistor2", "15" } });
            var options     = SetOptions("Get_order_client_card");
            var dbService   = new ClientCardDatabaseService(options);
            var clientCard2 = ClientCard.ConvertToClientCard(clientCardFromBody2);
            var clientCard  = ClientCard.ConvertToClientCard(ClientCardFromBody);
            var context     = new ClientCardContext(options);

            dbService.AddClientCardWithContext(clientCard2, context);
            dbService.AddClientCardWithContext(clientCard, context);
            var db = dbService.GetAllClientCardsWithContext(context);

            db.First().ContractId.Should().Be(1);
        }
Пример #2
0
        public void CanConvertToClientCard()
        {
            var clientCard = ClientCard.ConvertToClientCard(this.clientCardFromBody);

            SetDefaultGuid(this.client, clientCard);
            clientCard.Should().BeEquivalentTo(this.client);
        }
Пример #3
0
        public void CanNotConvertNullToCardClient()
        {
            ClientCardFromBody clientFromBody = null;

            Action act = () => ClientCard.ConvertToClientCard(clientFromBody);

            act.Should().Throw <EntitiesException>()
            .WithMessage("Input can not be null");
        }
Пример #4
0
        public void CanGetAllClientCards()
        {
            var options    = SetOptions("Get_all_client_card");
            var dbService  = new ClientCardDatabaseService(options);
            var clientCard = ClientCard.ConvertToClientCard(ClientCardFromBody);
            var context    = new ClientCardContext(options);

            dbService.AddClientCardWithContext(clientCard, context);
            var db = dbService.GetAllClientCardsWithContext(context);

            db.FirstOrDefault()?.Works.FirstOrDefault()?.Name.Should().Be("sr");
        }
Пример #5
0
        public void CanAddRepairEquipments()
        {
            var options    = SetOptions("Add_repair_equipments");
            var dbService  = new ClientCardDatabaseService(options);
            var clientCard = ClientCard.ConvertToClientCard(ClientCardFromBody);
            var context    = new ClientCardContext(options);

            dbService.AddClientCardWithContext(clientCard, context);
            var db = dbService.GetAllClientCardsWithContext(context);

            db.FirstOrDefault()?.RepairEquipments.FirstOrDefault()?.Name.Should().Be("resistor1");
        }
Пример #6
0
        public void CanGetContractCount()
        {
            var options    = SetOptions("Get_count_client_card");
            var dbService  = new ClientCardDatabaseService(options);
            var clientCard = ClientCard.ConvertToClientCard(ClientCardFromBody);
            var context    = new ClientCardContext(options);

            dbService.AddClientCardWithContext(clientCard, context);
            var count = dbService.GetContractCountWithContext(context);

            count.Should().Be(1);
        }
Пример #7
0
 public IActionResult Save([FromBody] ClientCardFromBody clientCardFromBody)
 {
     try
     {
         var clientCard = ClientCard.ConvertToClientCard(clientCardFromBody);
         var xmlData    = ClientCardSerializeService.SerializeDataToXml(clientCard, this.encode);
         var bytes      = this.encode.GetBytes(xmlData);
         return(this.File(bytes, "application/otcet-stream", "client.xml"));
     }
     catch (EntitiesException ex)
     {
         return(this.StatusCode(406, ex.Message));
     }
 }
Пример #8
0
        public void CanNotPutDateYearOverThreeThousand()
        {
            var clientFromBody = new ClientCardFromBody(
                "1",
                "Антон",
                "ЕКБ",
                "8",
                "*****@*****.**",
                "TV",
                "Display",
                "Sergey",
                "123",
                new DateTime(3050, 01, 01),
                new DateTime(2018, 03, 01),
                new[] { "sr" },
                new[] { new[] { "resistor1", "10" }, new[] { "resistor2", "15" } });

            Action act = () => ClientCard.ConvertToClientCard(clientFromBody);

            act.Should().Throw <EntitiesException>()
            .WithMessage("Invalid year");
        }
Пример #9
0
        public void CanNotConvertToCardClientWithoutWorks()
        {
            var clientFromBody = new ClientCardFromBody(
                "1",
                "Антон",
                "ЕКБ",
                "8",
                "*****@*****.**",
                "TV",
                "Display",
                "Sergey",
                "123",
                new DateTime(2018, 01, 01),
                new DateTime(2018, 03, 01),
                new string[] { },
                new[] { new[] { "resistor1", "10" }, new[] { "resistor2", "15" } });

            Action act = () => ClientCard.ConvertToClientCard(clientFromBody);

            act.Should().Throw <EntitiesException>()
            .WithMessage("Works can not be null");
        }
Пример #10
0
        public IActionResult SaveDatabase([FromBody] ClientCardFromBody clientCardFromBody)
        {
            ClientCard clientCard;

            try
            {
                clientCard = ClientCard.ConvertToClientCard(clientCardFromBody);
            }
            catch (EntitiesException ex)
            {
                return(this.StatusCode(406, ex.Message));
            }

            try
            {
                this.dbService.AddClientCardWithContext(clientCard, this.context);
                return(this.Ok("Saved"));
            }
            catch (DatabaseException ex)
            {
                return(this.StatusCode(208, ex.Message));
            }
        }