public ContextObject(IEnterprise enterprise) { if (enterprise == null) { throw new ArgumentException("enterprise is null"); } //Context=null时,说明没有初始化过,如果有初始化过,不再初始化 if (ServiceSession.Context == null) { using (new SystemWritablePolicy()) { PlatformContext.Current.EnterpriseID = enterprise.Code; PlatformContext.Current.EnterpriseName = enterprise.Name; } } else { if (PlatformContext.Current.EnterpriseID != enterprise.Code) { throw new U9ContextException("同一个请求中,不允许切换不同的企业"); } } //初始化上下文 InitContext(); }
// Impure Methods public void Add(IEnterprise enterprise) { if (_enterprise != null) { return; } _enterprise = enterprise; }
protected void Setup() { _subject = new Customer(); _enterprise = Substitute.For <IEnterprise>(); _subject.AddEnterprise(_enterprise); _dayTime = new DayTime(); }
public CommonService(IState state, IShippingMethod shippingMethod, ISuggestCourse suggestCourse, IEnterprise enterprise, IIndustry industry, IOrganizationContact contact, IMenu menu, IClientType cientType) { _state = state; _shippingMethod = shippingMethod; _suggestCourse = suggestCourse; _enterprise = enterprise; _industry = industry; _contact = contact; _menu = menu; _cientType = cientType; }
public void whenUninitialized_throwsInvalidOperationException() { // arrange: IEnvironment environment = null; IEnterprise enterprise = null; // assert: Assert.AreEqual("Uninitialized", Application.Name); Assert.Throws <InvalidOperationException>(delegate { environment = Application.Environment; }); Assert.Throws <InvalidOperationException>(delegate { enterprise = Application.Enterprise; }); Assert.IsNull(environment); Assert.IsNull(enterprise); }
public void Deserialization_returnApplicationEnterpriseInstance() { // arrange: EnterpriseBase enterprise = CreateNewEnterpriseToTestSerialization(); ApplicationBase app = new Fakes.FakeApplication(null, enterprise); Application.Initialize(app); Stream stream = TestUtilities.Serialize <IEnterprise>(enterprise); // act: IEnterprise deserialized = TestUtilities.Deserialize <IEnterprise>(stream); // assert: Assert.AreSame(enterprise, deserialized); }
protected void SetUp() { _plant1 = Substitute.For <IPlant>(); _plant1.Name.Returns(PLANT1_NAME); _wo1 = Substitute.For <IWork>(); _plant1.ShipToOtherPlants().Returns(new Dictionary <IWork, string>() { { _wo1, PLANT2_NAME } }); _plant2 = Substitute.For <IPlant>(); _plant2.Name.Returns(PLANT2_NAME); _wo2 = Substitute.For <IWork>(); _plant2.ShipToOtherPlants().Returns(new Dictionary <IWork, string>() { { _wo2, PLANT1_NAME } }); var dock = Substitute.For <IReceive>(); dock.Name.Returns("Shipping Dock"); _plant1.Dock().Returns(dock); _plant2.Dock().Returns(dock); _enterprise = Substitute.For <IEnterprise>(); _enterprise.Plants.Returns(new List <IPlant>() { _plant1, _plant2 }); _first = new DayTime(); _routes = new Dictionary <DayTime, string>() { { _first.CreateTimestamp(10), PLANT1_NAME }, { _first.CreateTimestamp(20), PLANT2_NAME }, { _first.CreateTimestamp(30), PLANT1_NAME }, { _first.CreateTimestamp(40), PLANT2_NAME } }; _subject = new Transport(_enterprise, _routes); }
public void whenInitialized_forwardToApplicationSingleton() { // arrange: string appName = "SampleApp"; EnvironmentBase environment = MockRepository.GenerateStrictMock <EnvironmentBase>(); IEnterprise enterprise = MockRepository.GenerateStrictMock <IEnterprise>(); ApplicationBase appSingleton = MockRepository.GeneratePartialMock <ApplicationBase>(appName); appSingleton.Expect(a => a.Environment).Return(environment).Repeat.Once(); appSingleton.Expect(a => a.Enterprise).Return(enterprise).Repeat.Once(); // act: Application.Initialize(appSingleton); // assert: Assert.AreEqual(appName, Application.Name); Assert.AreSame(environment, Application.Environment); Assert.AreSame(enterprise, Application.Enterprise); appSingleton.VerifyAllExpectations(); }
public FakeApplication(EnvironmentBase environment, IEnterprise enterprise) : this("Fake Application") { _environment = environment; _enterprise = enterprise; }
public Customer() { _enterprise = null; _orders = new List <Order>(); }
public FakeApplication(EnvironmentBase environment, IEnterprise enterprise) : this("Fake Application") { _environment = environment; _enterprise = enterprise; }
public void Add(IEnterprise enterprise) { return; // Don't use }