Ejemplo n.º 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);
        }
        public IList <ClientCard> GetAllClientCardsWithContext(ClientCardContext context)
        {
            var clientCards       = context.ClientCards.ToList();
            var orderedEnumerable = clientCards.OrderBy(c => c.ContractId).Select(c => c).ToList();

            return(orderedEnumerable);
        }
Ejemplo n.º 3
0
        public void GetContractCountShouldBeZero()
        {
            var options   = SetOptions("Get_zero_count_client_card");
            var dbService = new ClientCardDatabaseService(options);
            var context   = new ClientCardContext(options);
            var count     = dbService.GetContractCountWithContext(context);

            count.Should().Be(0);
        }
Ejemplo n.º 4
0
        public DataController()
        {
            var optionsBuilder = new DbContextOptionsBuilder <ClientCardContext>();

            optionsBuilder
            .UseLazyLoadingProxies()
            .UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=clientcardsnew1db;Trusted_Connection=True;");
            this.options   = optionsBuilder.Options;
            this.dbService = new ClientCardDatabaseService(this.options);
            this.context   = new ClientCardContext(this.options);
        }
Ejemplo n.º 5
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");
        }
Ejemplo n.º 6
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");
        }
Ejemplo n.º 7
0
        public void CanNotAddDoubleClientCard()
        {
            var options   = SetOptions("Add_double_to_database");
            var dbService = new ClientCardDatabaseService(options);
            var context   = new ClientCardContext(options);

            dbService.AddClientCardWithContext(this.clientCard, context);
            Action act = () => dbService.AddClientCardWithContext(this.clientCard, context);

            act.Should().Throw <DatabaseException>()
            .WithMessage("ContractId already exists");
        }
Ejemplo n.º 8
0
        public void CanAddClientCard()
        {
            var options   = SetOptions("Add_writes_to_database");
            var dbService = new ClientCardDatabaseService(options);
            var context   = new ClientCardContext(options);

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

            db.FirstOrDefault()?.ClientName.Should().Be("Антон");
            db.FirstOrDefault()?.Works.FirstOrDefault()?.Name.Should().Be("sr");
        }
Ejemplo n.º 9
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);
        }
        public void AddClientCardWithContext(ClientCard clientCard, ClientCardContext context)
        {
            var res = context.ClientCards.FirstOrDefault(p => p.ContractId == clientCard.ContractId);

            if (res == null)
            {
                context.Add(clientCard);
                context.SaveChanges();
            }
            else
            {
                throw new DatabaseException("ContractId already exists");
            }
        }
 public int GetContractCountWithContext(ClientCardContext context)
 {
     return(context.ClientCards.Count());
 }