public void UpdateKey_Pass_ReturnKey() { // Arrange newKey = tu.CreateApiKeyObject(); var expected = newKey.Key; // Act using (_db = tu.CreateDataBaseContext()) { IApiKeyService _apiKeyService = new ApiKeyService(_db); newKey = _apiKeyService.CreateKey(newKey); _db.SaveChanges(); newKey.Key = "A new Key"; var response = _apiKeyService.UpdateKey(newKey); _db.SaveChanges(); var result = _db.Keys.Find(newKey.Id); // Assert Assert.IsNotNull(response); Assert.IsNotNull(result); Assert.AreEqual(result.Id, newKey.Id); Assert.AreNotEqual(expected, result.Key); _apiKeyService.DeleteKey(newKey.Id); _db.SaveChanges(); } }
public void DeleteKey_Fail_NonExistingKeyShouldReturnNull() { // Arrange Guid nonExistingId = Guid.NewGuid(); var expected = nonExistingId; using (_db = new DatabaseContext()) { // Act var response = ApiKeyService.DeleteKey(_db, nonExistingId); _db.SaveChanges(); var result = _db.Keys.Find(expected); // Assert Assert.IsNull(response); Assert.IsNull(result); } }
public void CreateKey_Pass_ReturnKey() { // Arrange newKey = tu.CreateApiKeyObject(); var expected = newKey; using (_db = tu.CreateDataBaseContext()) { // Act var response = ApiKeyService.CreateKey(_db, newKey); _db.SaveChanges(); // Assert Assert.IsNotNull(response); Assert.AreEqual(response.Id, expected.Id); ApiKeyService.DeleteKey(_db, newKey.Id); _db.SaveChanges(); } }
public void GetApiKeyByAppIdIsUsed_Pass_ReturnKey() { // Arrange newKey = tu.CreateApiKeyObject(); var expected = newKey; // Act using (_db = tu.CreateDataBaseContext()) { newKey = ApiKeyService.CreateKey(_db, newKey); _db.SaveChanges(); var result = ApiKeyService.GetKey(_db, newKey.ApplicationId, false); // Assert Assert.IsNotNull(result); Assert.AreEqual(expected.Key, result.Key); ApiKeyService.DeleteKey(_db, newKey.Id); _db.SaveChanges(); } }
public void CreateKey_Fail_ExistingKeyShouldReturnNull() { // Arrange newKey = tu.CreateApiKeyObject(); var expected = newKey; using (_db = tu.CreateDataBaseContext()) { // Act var response = ApiKeyService.CreateKey(_db, newKey); _db.SaveChanges(); var actual = ApiKeyService.CreateKey(_db, newKey); // Assert Assert.IsNull(actual); Assert.AreNotEqual(expected, actual); ApiKeyService.DeleteKey(_db, newKey.Id); _db.SaveChanges(); } }
public void GetApiKeyByKey_Pass_ReturnKey() { // Arrange newKey = tu.CreateApiKeyObject(); var expected = newKey; // Act using (_db = tu.CreateDataBaseContext()) { IApiKeyService _apiKeyService = new ApiKeyService(_db); newKey = _apiKeyService.CreateKey(newKey); _db.SaveChanges(); var result = _apiKeyService.GetKey(newKey.Key); // Assert Assert.IsNotNull(result); Assert.AreEqual(expected.Key, result.Key); _apiKeyService.DeleteKey(newKey.Id); _db.SaveChanges(); } }