public void Should_not_refresh_readonly_property() { DISetup.SetupContainer(); DISetup.Container.Register <FakeModel>(); var model = DISetup.Container.GetInstance <FakeModel>(); model.Dummy4 = new List <FakeLocalizableWithReadonlyProperty>() { new FakeLocalizableWithReadonlyProperty() }; var changedEvents = new List <string>(); var changingEvents = new List <string>(); model.Dummy4.First().PropertyChanged += (s, e) => { changedEvents.Add(e.PropertyName); }; model.Dummy4.First().PropertyChanging += (s, e) => { changingEvents.Add(e.PropertyName); }; var invocation = new Mock <Castle.DynamicProxy.IInvocation>(); invocation.Setup(p => p.InvocationTarget).Returns(model); invocation.Setup(p => p.Proxy).Returns(model.Dummy4); var prop = model.GetType().GetProperty("Dummy4"); var args = new LocalizationRefreshArgs(invocation.Object, prop); var handler = new LocalizationCollectionRefreshHandler(); handler.Refresh(args); changedEvents.Count.Should().Be(0); changingEvents.Count.Should().Be(0); }
public void CanRefresh_should_be_false() { var fake = new FakeModel(); var prop = fake.GetType().GetProperty("Dummy1"); var handler = new LocalizationCollectionRefreshHandler(); var args = new LocalizationRefreshArgs(null, prop); handler.CanRefresh(args).Should().BeFalse(); }
/// <summary> /// Processes the locale changed. /// </summary> /// <param name="invocation">The invocation.</param> private void ProcessLocaleChanged(IInvocation invocation) { var localizationProperties = invocation.TargetType.GetProperties().Where(p => Attribute.IsDefined(p, typeof(LocalizationAttributeBase))); if (localizationProperties.Count() > 0) { foreach (var prop in localizationProperties) { ((ILocalizableModel)invocation.Proxy).OnPropertyChanging(prop.Name); ((ILocalizableModel)invocation.Proxy).OnPropertyChanged(prop.Name); var args = new LocalizationRefreshArgs(invocation, prop); var refreshHandler = refreshHandlers.FirstOrDefault(p => p.CanRefresh(args)); if (refreshHandler != null) { refreshHandler.Refresh(args); } } } }
public void Should_refresh_property() { DISetup.SetupContainer(); DISetup.Container.Register <FakeModel>(); var model = DISetup.Container.GetInstance <FakeModel>(); model.Dummy2 = new List <FakeLocalizableModel>() { new FakeLocalizableModel() { FakeProp = "1" } }; var changedEvents = new List <string>(); var changingEvents = new List <string>(); var initialValue = model.Dummy2.First().FakeProp; var finalValue = string.Empty; model.Dummy2.First().PropertyChanged += (s, e) => { changedEvents.Add(e.PropertyName); }; model.Dummy2.First().PropertyChanging += (s, e) => { changingEvents.Add(e.PropertyName); }; var invocation = new Mock <Castle.DynamicProxy.IInvocation>(); invocation.Setup(p => p.InvocationTarget).Returns(model); invocation.Setup(p => p.Proxy).Returns(model.Dummy2); var prop = model.GetType().GetProperty("Dummy2"); var args = new LocalizationRefreshArgs(invocation.Object, prop); var handler = new LocalizationCollectionRefreshHandler(); handler.Refresh(args); changedEvents.Count.Should().Be(2); changedEvents.GroupBy(s => s).Select(s => s.First()).Count().Should().Be(1); changingEvents.Count.Should().Be(2); changingEvents.GroupBy(s => s).Select(s => s.First()).Count().Should().Be(1); model.Dummy2.First().FakeProp.Should().Be(initialValue); }
/// <summary> /// Refreshes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> /// <exception cref="NotImplementedException"></exception> public void Refresh(LocalizationRefreshArgs args) { args.Property.SetValue(args.Invocation.InvocationTarget, "Refresh value"); }
/// <summary> /// Determines whether this instance can refresh the specified arguments. /// </summary> /// <param name="args">The arguments.</param> /// <returns><c>true</c> if this instance can refresh the specified arguments; otherwise, <c>false</c>.</returns> /// <exception cref="NotImplementedException"></exception> public bool CanRefresh(LocalizationRefreshArgs args) { return(true); }