public void MigrateUsersStorageProviderData() { var mocks = new MockRepository(); var source = mocks.StrictMock <IUsersStorageProviderV30>(); var destination = mocks.StrictMock <IUsersStorageProviderV30>(); // Setup SOURCE -------------------- // User groups var g1 = new UserGroup("G1", "G1", source); var g2 = new UserGroup("G2", "G2", source); Expect.Call(source.GetUserGroups()).Return(new[] { g1, g2 }); // Users var u1 = new UserInfo("U1", "U1", "*****@*****.**", true, DateTime.Now, source); var u2 = new UserInfo("U2", "U2", "*****@*****.**", true, DateTime.Now, source); var u3 = new UserInfo("U3", "U3", "*****@*****.**", true, DateTime.Now, source); Expect.Call(source.GetUsers()).Return(new[] { u1, u2, u3 }); // Membership g1.Users = new[] { u1.Username, u2.Username }; g2.Users = new[] { u2.Username, u3.Username }; u1.Groups = new[] { g1.Name }; u2.Groups = new[] { g1.Name, g2.Name }; u3.Groups = new[] { g2.Name }; // User data IDictionary <string, string> u1Data = new Dictionary <string, string> { { "Key1", "Value1" }, { "Key2", "Value2" } }; Expect.Call(source.RetrieveAllUserData(u1)).Return(u1Data); Expect.Call(source.RetrieveAllUserData(u2)).Return(new Dictionary <string, string>()); Expect.Call(source.RetrieveAllUserData(u3)).Return(new Dictionary <string, string>()); // Setup DESTINATION ------------------ // User groups var g1Out = new UserGroup(g1.Name, g1.Description, destination); var g2Out = new UserGroup(g2.Name, g2.Description, destination); Expect.Call(destination.AddUserGroup(g1.Name, g1.Description)).Return(g1Out); Expect.Call(destination.AddUserGroup(g2.Name, g2.Description)).Return(g2Out); // Users var u1Out = new UserInfo(u1.Username, u1.DisplayName, u1.Email, u1.Active, u1.DateTime, destination); var u2Out = new UserInfo(u2.Username, u2.DisplayName, u2.Email, u2.Active, u2.DateTime, destination); var u3Out = new UserInfo(u3.Username, u3.DisplayName, u3.Email, u3.Active, u3.DateTime, destination); Expect.Call(destination.AddUser(u1.Username, u1.DisplayName, null, u1.Email, u1.Active, u1.DateTime)) .Return(u1Out) .Constraints( RMC.Is.Equal(u1.Username), RMC.Is.Equal(u1.DisplayName), RMC.Is.Anything(), RMC.Is.Equal(u1.Email), RMC.Is.Equal(u1.Active), RMC.Is.Equal(u1.DateTime)); Expect.Call(destination.AddUser(u2.Username, u2.DisplayName, null, u2.Email, u2.Active, u2.DateTime)) .Return(u2Out) .Constraints( RMC.Is.Equal(u2.Username), RMC.Is.Equal(u2.DisplayName), RMC.Is.Anything(), RMC.Is.Equal(u2.Email), RMC.Is.Equal(u2.Active), RMC.Is.Equal(u2.DateTime)); Expect.Call(destination.AddUser(u3.Username, u3.DisplayName, null, u3.Email, u3.Active, u3.DateTime)) .Return(u3Out) .Constraints( RMC.Is.Equal(u3.Username), RMC.Is.Equal(u3.DisplayName), RMC.Is.Anything(), RMC.Is.Equal(u3.Email), RMC.Is.Equal(u3.Active), RMC.Is.Equal(u3.DateTime)); // Membership Expect.Call(destination.SetUserMembership(u1Out, u1.Groups)).Return(u1Out); Expect.Call(destination.SetUserMembership(u2Out, u2.Groups)).Return(u2Out); Expect.Call(destination.SetUserMembership(u3Out, u3.Groups)).Return(u3Out); // User data Expect.Call(destination.StoreUserData(u1Out, "Key1", "Value1")).Return(true); Expect.Call(destination.StoreUserData(u1Out, "Key2", "Value2")).Return(true); // Delete source data Expect.Call(source.RemoveUser(u1)).Return(true); Expect.Call(source.RemoveUser(u2)).Return(true); Expect.Call(source.RemoveUser(u3)).Return(true); Expect.Call(source.RemoveUserGroup(g1)).Return(true); Expect.Call(source.RemoveUserGroup(g2)).Return(true); mocks.Replay(source); mocks.Replay(destination); DataMigrator.MigrateUsersStorageProviderData(source, destination, false); mocks.Verify(source); mocks.Verify(destination); }