I have a few unit tests that when I run all 700 together they pass but when I run them by there manager they fail. I have Visual Studio 2013 and R# 8.
Manager Code:
public GPermission CreatePerm(string user, string gId, string org, GPerm permissions)
{
ThrowHelper.CheckArgumentNullOrEmpty(user, "user");
ThrowHelper.CheckArgumentNullOrEmpty(gId, "gId");
ThrowHelper.CheckArgumentNullOrEmpty(org, "org");
GPermission currentUserPerm = m_GPermStore.GetPerm(gId, m_CurrentUserId);
if (currentUserPerm == null || !currentUserPerm.HasPermission(GPerm.Admin))
{
throw m_Diagnostics.ThrowPermException(m_CurrentUserId, gId);
}
GPermission newPrivilege = new GPermission();
newPrivilege.PrivilegeId = Guid.NewGuid().ToString().Replace("-", "");
newPrivilege.user = user;
newPrivilege.gId = gId;
newPrivilege.org = org;
newPrivilege.Permissions = permissions;
m_GPermStore.AddOrUpdate(new[]{newPrivilege});
GPermission createdPrivilege = m_GPermStore.GetPerm(gId, user);
CacheHandler.ClearGCache(gId);
return createdPrivilege;
}
Unit Test:
[TestMethod]
public void GPM_CreateSuccess()
{
IGPermStore stubGPermStore = new StubIGPermStore
{
GetPermStringString = (gId, user) =>
{
if (user == "testUserId")
{
return new GPermission
{
Permissions = GPerm.Admin,
PrivilegeId = "privId"
};
}
return gPrivateCollection.FirstOrDefault(p => p.user == user);
},
AddOrUpdateIEnumerableOfGPermission = permisisons =>
{
foreach (GPermission perm in permisisons)
{
GPermission foundPrivilege = gPrivateCollection.FirstOrDefault
(p => p.gId == perm.gId && p.user == perm.user);
if (foundPrivilege == null)
{
gPrivateCollection.Add(perm);
}
}
}
};
m_server.GPermStoreStubs = stubGPermStore;
m_GPermissionManager = ThrowHelper.GetServiceOrThrow<IGPermissionManager>(m_server);
GPermission insertedPrivNode = m_GPermissionManager.CreatePrivilege("user", "gId", "org", GPerm.Member);
Assert.IsNotNull(insertedPrivNode);
Assert.IsTrue(gPrivateCollection.Count == 1);
GPermission gPrivateCollection1 = gPrivateCollection[0];
Assert.AreEqual(insertedPrivNode.user, gPrivateCollection1.user);
Assert.AreEqual(insertedPrivNode.gId, gPrivateCollection1.gId);
Assert.AreEqual(insertedPrivNode.OrganizationId, gPrivateCollection1.OrganizationId);
Assert.AreEqual(insertedPrivNode.Permissions, gPrivateCollection1.Permissions);
Assert.AreEqual(insertedPrivNode.user, "user");
Assert.AreEqual(insertedPrivNode.gId, "gId");
Assert.AreEqual(insertedPrivNode.OrganizationId, "org");
Assert.AreEqual(insertedPrivNode.Permissions, GPermission.Member);
}
I am wondering that if there is something I should be asserting so that I can trip it to fail every-time instead of only when I run it by itself. I know whats wrong but I can't be confident in the test if they all pass during a build.
Edit: The thing that is wrong is the cache is not set to test worker. Here is the code it fails on:
public static void ClearGCache(string gId)
{
if (!IsTest)
{
if (currentConnect == null)
{
currentConnect = ConnectionMultiplexer.Connect(CloudConfigurationManager.GetSetting("RedisCacheConnectionString"));
}
IData cache = currentConnect.GetData();
cache.KeyDelete("users-" + gId);
}
}
I simply don't have the test flag as true.