public void Get_appExists_shouldReturnApp()
        {
            // Arrange
            var repository = new DapperAppRepository(Connection, AppTableName);
            var appId = Guid.NewGuid();
            var serviceId = Guid.NewGuid();
            var createdAt = DateTime.UtcNow;
            const string secret = "testsecret";
            const string name = "user1";
            QueryFromFile(InsertAppScriptFilename, new Dictionary<string, string>
            {
                { "AppId", appId.ToString() },
                { "ServiceId", serviceId.ToString() },
                { "Secret", secret },
                { "Enabled", "1"},
                { "CreatedAt", createdAt.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) },
                { "Name", name },
            });

            // Act
            var actual = repository.Get(appId, serviceId);

            // Assert
            Assert.AreEqual(appId, actual.AppId);
            Assert.AreEqual(serviceId, actual.ServiceId);
            Assert.AreEqual(secret, actual.Secret);
            Assert.AreEqual(createdAt.Date, actual.CreatedAt.Date);
            Assert.IsTrue(actual.Enabled);
            Assert.IsTrue(actual.Id > 0);
            Assert.AreEqual(name, actual.Name);
        }
        public void Get_appDoesNotExist_shouldReturnNull()
        {
            // Arrange
            var repository = new DapperAppRepository(Connection, AppTableName);
            var appId = Guid.NewGuid();
            var serviceId = Guid.NewGuid();

            // Act
            var actual = repository.Get(appId, serviceId);

            // Assert
            Assert.AreEqual(null, actual);
        }
        public void Get_byIdAppDoesNotExist_shouldReturnNull()
        {
            // Arrange
            var repository = new DapperAppRepository(Connection, AppTableName);

            // Act
            var actual = repository.Get(23);

            // Assert
            Assert.AreEqual(null, actual);
        }
        public void Get_byIdAppExists_shouldReturnApp()
        {
            // Arrange
            var repository = new DapperAppRepository(Connection, AppTableName);
            var appId = Guid.NewGuid();
            var serviceId = Guid.NewGuid();
            var createdAt = DateTime.Now;
            const string secret = "testsecret";
            const string name = "user1";
            var app = new AppModel
            {
                AppId = appId,
                ServiceId = serviceId,
                Secret = secret,
                Enabled = true,
                CreatedAt = createdAt,
                Name = name,
            };
            var id = repository.Insert(app);

            // Act
            var actual = repository.Get(id);

            // Assert
            Assert.AreEqual(appId, actual.AppId);
            Assert.AreEqual(serviceId, actual.ServiceId);
            Assert.AreEqual(secret, actual.Secret);
            Assert.AreEqual(createdAt.Date, actual.CreatedAt.Date);
            Assert.IsTrue(actual.Enabled);
            Assert.IsTrue(actual.Id > 0);
            Assert.AreEqual(name, actual.Name);
        }
        public void Update_appExistsValidData_shouldUpdateApp()
        {
            var repository = new DapperAppRepository(Connection, AppTableName);
            var app = CreateApp();
            app.Enabled = true;
            var id = repository.Insert(app);

            app = CreateApp();
            app.Enabled = false;
            repository.Update(id, app);

            var actual = repository.Get(id);
            app.Id = id;
            Assert.AreEqual(app, actual);
        }
        public void Delete_appDoesNotExists_shouldHaveNoImpact()
        {
            // Arrange
            var repository = new DapperAppRepository(Connection, AppTableName);
            var appId = Guid.NewGuid();
            var serviceId = Guid.NewGuid();
            var createdAt = DateTime.Now;
            const string secret = "testsecret";
            const string name = "user1";
            QueryFromFile(InsertAppScriptFilename, new Dictionary<string, string>
            {
                { "AppId", appId.ToString() },
                { "ServiceId", serviceId.ToString() },
                { "Secret", secret },
                { "Enabled", "1"},
                { "CreatedAt", createdAt.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) },
                { "Name", name },
            });
            var added = repository.Get(appId, serviceId);
            Assert.AreNotEqual(null, added);
            var expected = repository.GetAll().Count();

            // Act
            repository.Delete(added.Id.Value + 1);

            // Assert
            var actual = repository.GetAll().Count();
            Assert.AreEqual(expected, actual);
        }