public void Update(int id, AppModel user) { if (Get(id) == null) { throw new ArgumentException("App not found: " + id); } _connection.Query( String.Format(@" UPDATE {0} SET Name = @Name, AppId = @AppId, ServiceId = @ServiceId, Enabled = @Enabled, Secret = @Secret, CreatedAt = @CreatedAt WHERE id = @id", _tableName), new { id, user.Name, user.ServiceId, user.AppId, user.Enabled, user.CreatedAt, user.Secret }); }
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 int Insert(AppModel app) { return _connection.Query<int>( String.Format(@" DECLARE @InsertedRows AS TABLE (Id int); INSERT INTO {0} OUTPUT Inserted.Id INTO @InsertedRows VALUES (@AppId, @ServiceId, @Secret, @Enabled, @CreatedAt, @Name); SELECT Id FROM @InsertedRows;", _tableName), new {app.AppId, app.ServiceId, app.Secret, app.Enabled, app.CreatedAt, app.Name}).Single(); }
protected bool Equals(AppModel other) { return Id == other.Id && AppId.Equals(other.AppId) && ServiceId.Equals(other.ServiceId) && string.Equals(Secret, other.Secret) && Enabled.Equals(other.Enabled) && CreatedAt.ToString(CultureInfo.InvariantCulture).Equals(other.CreatedAt.ToString(CultureInfo.InvariantCulture)) && string.Equals(Name, other.Name); }