Beispiel #1
0
        public void InsertAddsConnectionToDb()
        {
            var db   = new AppDbContext(appDbOptions);
            var repo = new ConnectorRepo(db, factory, new IOperationResource[] { });

            ConnectorViewModel model = new ConnectorViewModel
            {
                Name           = "name1",
                ResourceType   = "type1",
                RecordLimit    = 12,
                Port           = 123,
                InitialCatalog = "cat1",
                DataSource     = "src",
                UserId         = "id"
            };



            Guid id = repo.Insert(model);

            Connector actual;

            using (var db1 = new AppDbContext(appDbOptions))
            {
                actual = db1.Connector.First(c => c.Name == "name1");
            }

            Assert.AreEqual("type1", actual.ResourceType);
            Assert.AreEqual(12, actual.RecordLimit);
            Assert.AreEqual("cat1", connectionInformation.InitialCatalog);
            Assert.AreEqual("src", connectionInformation.DataSource);
            Assert.AreEqual("id", connectionInformation.UserId);
            Assert.AreEqual(123, actual.Port);
            Assert.AreEqual("conn1", actual.ConnectionString);
        }
Beispiel #2
0
        public void GetConnectorCountFromDb()
        {
            using (var db1 = new AppDbContext(appDbOptions))
            {
                db1.Connector.AddRange(new Connector
                {
                    Id   = Guid.NewGuid(),
                    Name = "name123",
                },
                                       new Connector
                {
                    Id   = Guid.NewGuid(),
                    Name = "aname123",
                });

                db1.SaveChanges();
            }

            var db   = new AppDbContext(appDbOptions);
            var repo = new ConnectorRepo(db, factory, new IOperationResource[] { });

            var count = repo.ConnectorCount();

            Assert.AreEqual(2, count);
        }
Beispiel #3
0
        public void DeleteConnectorRemovesFromDb()
        {
            using (var db1 = new AppDbContext(appDbOptions))
            {
                db1.Connector.AddRange(new Connector
                {
                    Id   = Guid.NewGuid(),
                    Name = "name123",
                },
                                       new Connector
                {
                    Id   = id,
                    Name = "aname123",
                });

                db1.SaveChanges();
            }

            var db   = new AppDbContext(appDbOptions);
            var repo = new ConnectorRepo(db, factory, new IOperationResource[] { });

            repo.Delete(id);

            using (var db1 = new AppDbContext(appDbOptions))
            {
                var results = db1.Connector.ToList();
                Assert.AreEqual(1, results.Count());
                Assert.AreEqual("name123", results.First().Name);
            }
        }
Beispiel #4
0
        public void ListConnectorsOrdersByName()
        {
            using (var db1 = new AppDbContext(appDbOptions))
            {
                db1.Connector.AddRange(new Connector
                {
                    Id   = id,
                    Name = "name123",
                },
                                       new Connector
                {
                    Id   = Guid.NewGuid(),
                    Name = "aname123",
                });

                db1.SaveChanges();
            }

            var db   = new AppDbContext(appDbOptions);
            var repo = new ConnectorRepo(db, factory, new IOperationResource[] { });

            var results = repo.ListConnectors();

            Assert.AreEqual(2, results.Count());
            Assert.AreEqual("aname123", results.First().Name);
        }
Beispiel #5
0
        public void GetConnectorById()
        {
            using (var db1 = new AppDbContext(appDbOptions))
            {
                db1.Connector.Add(new Connector
                {
                    Id               = id,
                    Name             = "name123",
                    ResourceType     = "type1",
                    ConnectionString = "conn1"
                });

                db1.SaveChanges();
            }

            var db       = new AppDbContext(appDbOptions);
            var resource = new Mock <IOperationResource>();

            resource.Setup(c => c.ResourceType).Returns("type1");
            var repo = new ConnectorRepo(db, factory, new IOperationResource[] { resource.Object });

            var actual = repo.GetById(id);

            Assert.AreEqual("name123", actual.Name);
        }
Beispiel #6
0
        public void Init()
        {
            var appDbOptions = new DbContextOptionsBuilder <AppDbContext>()
                               .UseInMemoryDatabase(databaseName: "appDb" + Guid.NewGuid().ToString())
                               .Options;

            db     = new AppDbContext(appDbOptions);
            repo   = new ConnectorRepo(db, Mock.Of <IConnectionStringFactory>(), new IOperationResource[] { });
            errors = new Dictionary <string, string>();
        }
Beispiel #7
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (Convert.ToDouble(GamePrice) <= Convert.ToDouble(moneyValue))
     {
         try
         {
             Connector connector = new Connector(Assets.Scripts.Login.UserLogin, Convert.ToInt32(GameID));
             ConnectorRepo.Insert(connector);
             Users user = new Users(Assets.Scripts.Login.UserLogin, User.Money);
             UsersRepo.Update(user, -1 * Convert.ToDouble(GamePrice));
             MessageBox.Show("Game was added to your account!");
             SetData();
         }
         catch
         {
         }
     }
 }