Last active
April 22, 2018 05:48
-
-
Save fasetto/d8df2fa533183672edc8092763d6f2fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestClass] | |
public class RepoTests | |
{ | |
UnitOfWork unitOfWork = new UnitOfWork(new MongoDataContext("mongodb://localhost:27017/sampledb")); | |
[TestInitialize] | |
public async Task Initialize() | |
{ | |
var serkan = new User() | |
{ | |
FirstName = "SERKAN", | |
LastName = "BIRCAN", | |
Email = "user@domain.com" | |
}; | |
await unitOfWork.Users.AddNewAsync(serkan); | |
} | |
[TestCleanup] | |
public async Task Cleanup() | |
{ | |
await unitOfWork.Users.DeleteAllAsync(); | |
} | |
[TestMethod] | |
public void CheckConnection_When_Db_Available() | |
{ | |
var isConnected = unitOfWork.CheckConnection(); | |
Assert.IsTrue(isConnected); | |
} | |
[TestMethod] | |
public async Task GetByField_When_Its_Exist() | |
{ | |
var users = await unitOfWork.Users.GetByFieldAsync("firstname", "SERKAN"); | |
Assert.IsTrue(users.Count() > 0); | |
} | |
[TestMethod] | |
public async Task UpdateTest() | |
{ | |
// Arrange | |
var users = await unitOfWork.Users.GetByFieldAsync("firstname", "SERKAN"); | |
var user = users.FirstOrDefault(); | |
// Act | |
var isUpdated = await unitOfWork.Users.UpdateAsync(user.Id, "email", "serkanbircan21@outlook.com"); | |
// Assert | |
users = await unitOfWork.Users.GetByFieldAsync("firstname", "SERKAN"); | |
user = users.FirstOrDefault(); | |
Assert.IsTrue(isUpdated); | |
Assert.AreEqual("serkanbircan21@outlook.com", user.Email); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment