示例#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 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);
        }
示例#3
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);
        }
示例#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 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");
        }
示例#7
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");
        }
示例#8
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);
        }