public void Deserialize_works() { // arrange: RoleBase role = new FakeRole(); RoleRef roleRef = new RoleRef(role); int numRef = 100; for(int i = 0; i < numRef; ++i) roleRef.Increase(); Stream stream = TestUtilities.Serialize(roleRef); // act: RoleRef deserialized = TestUtilities.Deserialize<RoleRef>(stream); int nextRef = deserialized.Increase(); // assert: Assert.AreEqual(numRef + 1, nextRef); }
public void Serialize_works() { // arrange: RoleBase role = new FakeRole(); RoleRef roleRef = new RoleRef(role); int numRef = 100; for(int i = 0; i < numRef; ++i) roleRef.Increase(); // act: Stream stream = TestUtilities.Serialize(roleRef); // assert: Assert.IsNotNull(stream); }
public void Achieve_anAlreadyAchievedRole_returnPreviousInstance() { // arrange: FakeRole roleToReturn = new FakeRole(); FakeWorkingSession session = GeneratePartialMock<FakeWorkingSession>(); IPrincipal owner = session.Owner; session.Expect(s => s.CallIsAllowed<IFakeRole>()).Return(true).Repeat.Once(); FakeRoleBuilder<IFakeRole, FakeRole> roleBuilder = GeneratePartialMock<FakeRoleBuilder<IFakeRole, FakeRole>>(); roleBuilder.Expect(b => b.CallCreateRoleFor(owner)).Return(roleToReturn).Repeat.Once(); session.Expect(s => s.CallGetRoleBuilder<IFakeRole>()).Return(roleBuilder).Repeat.Once(); IFakeRole achievedRole1 = null; session.Achieve<IFakeRole>(out achievedRole1); IFakeRole achievedRole2 = null; // act: session.Achieve<IFakeRole>(out achievedRole2); // assert: Assert.AreSame(achievedRole1, achievedRole2); }
public void Leave_withUnknownRoleReference_throwsArgumentException() { // arrange: IFakeRole unknownInstance = new FakeRole(); FakeRole roleToReturn = GeneratePartialMock<FakeRole>(); FakeWorkingSession session = GeneratePartialMock<FakeWorkingSession>(); IPrincipal owner = session.Owner; session.Expect(s => s.CallIsAllowed<IFakeRole>()).Return(true).Repeat.Once(); FakeRoleBuilder<IFakeRole, FakeRole> roleBuilder = GeneratePartialMock<FakeRoleBuilder<IFakeRole, FakeRole>>(); roleBuilder.Expect(b => b.CallCreateRoleFor(owner)).Return(roleToReturn).Repeat.Once(); session.Expect(s => s.CallGetRoleBuilder<IFakeRole>()).Return(roleBuilder).Repeat.Once(); IFakeRole achievedRole1 = null; session.Achieve<IFakeRole>(out achievedRole1); // assert: Assert.Throws<ArgumentException>(delegate { session.Leave<IFakeRole>(ref unknownInstance); }); Assert.IsNotNull(unknownInstance); }
public void CanAchieve_anAlreadyAchievedRole_dontCallIsAllowedTemplateMethod() { // arrange: FakeRole roleToReturn = new FakeRole(); FakeWorkingSession session = GeneratePartialMock<FakeWorkingSession>(); IPrincipal owner = session.Owner; session.Expect(s => s.CallIsAllowed<IFakeRole>()).Return(true).Repeat.Once(); FakeRoleBuilder<IFakeRole, FakeRole> roleBuilder = GeneratePartialMock<FakeRoleBuilder<IFakeRole, FakeRole>>(); roleBuilder.Expect(b => b.CallCreateRoleFor(owner)).Return(roleToReturn).Repeat.Once(); session.Expect(s => s.CallGetRoleBuilder<IFakeRole>()).Return(roleBuilder).Repeat.Once(); IFakeRole achievedRole1 = null; session.Achieve<IFakeRole>(out achievedRole1); // act: bool canAchieve = session.CanAchieve<IFakeRole>(); // assert: Assert.IsTrue(canAchieve); }