Click here to Skip to main content
15,793,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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;
   = org;
            newPrivilege.Permissions = permissions;


            GPermission createdPrivilege = m_GPermStore.GetPerm(gId, user);


            return createdPrivilege;

Unit Test:
public void GPM_CreateSuccess() //Unit Test for GCreate Permission
	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)
	m_server.GPermStoreStubs = stubGPermStore;

	m_GPermissionManager = ThrowHelper.GetServiceOrThrow<IGPermissionManager>(m_server);
	GPermission insertedPrivNode = m_GPermissionManager.CreatePrivilege("user", "gId", "org", GPerm.Member);
	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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900