public void RegisterTypeAsSingleton(Type implementation) { this.defaultContainer.Register( EntryBuilder.For(implementation) .WithLifestyle(Lifestyle.Singleton) ); }
public void RegisterTypeAsTransient(Type implementation) { this.defaultContainer.Register( EntryBuilder.For(implementation) .WithLifestyle(Lifestyle.Transient) ); }
public EntryBuilder AddEntry(Category category) { var builder = new EntryBuilder(); builder.Subject.Category = category; _entries.Add(builder); return(builder); }
public void RegisterInstance(IEnumerable <Type> contracts, object instance) { this.defaultContainer.Register( EntryBuilder.For(contracts.First()) .UsingInstance(instance) .WithLifestyle(Lifestyle.Singleton) ); }
public void RegisterAsSingleton(IEnumerable <Type> contracts, Type implementation) { this.defaultContainer.Register( EntryBuilder.For(contracts.First()) .ImplementedBy(implementation) .WithLifestyle(Lifestyle.Singleton) ); }
public void puzzleContainer_register_entry_should_report_entry_as_registered() { var container = new PuzzleContainer(); container.Register(EntryBuilder.For <Object>()); var actual = container.IsRegistered <Object>(); Assert.IsTrue(actual); }
public void puzzleContainer_register_entry_using_instance_should_resolve_the_given_instance_using_getService_as_singleton() { var container = new PuzzleContainer(); container.Register(EntryBuilder.For <Object>().UsingInstance(new Object())); var expected = container.GetService(typeof(Object)); var actual = container.GetService(typeof(Object)); Assert.AreEqual(expected, actual); }
public void puzzleContainer_register_entry_as_transient_should_resolve_instances_as_transient() { var container = new PuzzleContainer(); container.Register(EntryBuilder.For <Object>().WithLifestyle(Lifestyle.Transient)); var i1 = container.Resolve <Object>(); var i2 = container.Resolve <Object>(); Assert.AreNotEqual(i1, i2); }
public void Add_WhenNotAddedAllEntryLines_ShouldCompleteEntryBeNull() { // Arrange var testee = new EntryBuilder(); // Act testee.Add(new ParseResult(LineType.MessageId, "The msgid text"), 1); // Assert testee.CompleteEntry.Should().BeNull(); }
public void puzzleContainer_register_entry_using_instance_should_resolve_the_given_instance() { var expected = new Object(); var container = new PuzzleContainer(); container.Register(EntryBuilder.For <Object>().UsingInstance(expected)); var actual = container.Resolve <Object>(); Assert.AreEqual(expected, actual); }
public void PuzzleContainer_resolve_using_type_with_static_type_initializer_should_not_fail() { var container = new PuzzleContainer(); container.Register( EntryBuilder.For <TypeWithStaticCtor>() ); var actual = container.Resolve <TypeWithStaticCtor>(); Assert.IsNotNull(actual); }
public void puzzleContainer_register_should_raise_componentRegistered_event_with_a_reference_to_the_registered_entry() { IContainerEntry expected = EntryBuilder.For <Object>(); IContainerEntry actual = null; var container = new PuzzleContainer(); container.ComponentRegistered += (s, e) => actual = e.Entry; container.Register(expected); Assert.AreEqual(expected, actual); }
public void puzzleContainer_register_should_raise_componentRegistered_event() { var expected = 1; var actual = 0; var container = new PuzzleContainer(); container.ComponentRegistered += (s, e) => actual++; container.Register(EntryBuilder.For <Object>()); Assert.AreEqual(expected, actual); }
private static Entry BuildEntry( NavigationTimingWrapper.NavTiming timing, string URL, IList <string> pathArgumentList) { EntryBuilder eb = new EntryBuilder(pathArgumentList); eb.Unit = "Milliseconds"; eb.Value = timing.Value; eb.Url = URL; return(eb.Build()); }
public static Entry FromProperties(IDictionary <string, object> entryProperties) { const bool isRequired = true; IList <string> path = getPath(entryProperties, isRequired); long timestamp = getTimestamp(entryProperties, isRequired); EntryBuilder entryBuilder = new EntryBuilder(path, timestamp); object objectValue = entryProperties[Value]; if (objectValue != null) { try { double value = Convert.ToDouble(objectValue.ToString()); entryBuilder.Value = value; } catch (System.FormatException nfe) { throw new NeotysAPIException(NeotysAPIException.ErrorType.NL_API_INVALID_ARGUMENT, "Invalid entry value: " + objectValue, nfe); } } object objectUrl = entryProperties[Url]; if (objectUrl != null) { entryBuilder.Url = objectUrl.ToString(); } object objectUnit = entryProperties[Unit]; if (objectUnit != null) { entryBuilder.Unit = Escaper.Escape(objectUnit.ToString()); } object objectStatus = entryProperties[Statuses.ElementName]; if (objectStatus != null) { if (!(objectStatus is IDictionary <string, object>)) { throw new NeotysAPIException(NeotysAPIException.ErrorType.NL_API_INVALID_ARGUMENT, "Invalid entry status: " + objectStatus); } Status status = Statuses.FromProperties((IDictionary <string, object>)objectStatus); if (status != null) { entryBuilder.Status = status; } } return(entryBuilder.Build()); }
public void PuzzleContainer_entryBuilder_should_support_contract_forwarding() { var entry = EntryBuilder.For <IFoo>() .Forward <IBar>() .ImplementedBy <TypeWithMultipleContracts>(); var sut = new PuzzleContainer(); sut.Register(entry); var actual = sut.IsRegistered <IBar>(); Assert.IsTrue(actual); }
public void puzzleContainer_register_entries_using_valid_entry_should_resolve_the_given_entries() { var container = new PuzzleContainer(); IContainerEntry e1 = EntryBuilder.For <ArgumentException>(); IContainerEntry e2 = EntryBuilder.For <ArgumentNullException>(); container.Register(new[] { e1, e2 }); var obj1 = container.Resolve <ArgumentException>(); var obj2 = container.Resolve <ArgumentNullException>(); Assert.IsNotNull(obj1); Assert.IsNotNull(obj2); }
public void Add_WhenAddedAllEntryLinesAndAddingNextEntryLine_ShouldSetCompleteEntry() { // Arrange var testee = new EntryBuilder(); testee.Add(new ParseResult(LineType.MessageId, "The msgid text"), 1); testee.Add(new ParseResult(LineType.MessageString, "The msgstr text"), 2); // Act testee.Add(new ParseResult(LineType.MessageId, "The msgid text"), 3); // Assert testee.CompleteEntry.Should().NotBeNull(); }
public void Add_WhenMsgstrIsOnOneLine_ShouldTakeText() { // Arrange var testee = new EntryBuilder(); testee.Add(new ParseResult(LineType.MessageId, "The msgid text"), 1); testee.Add(new ParseResult(LineType.MessageString, "The msgstr text"), 2); // Act testee.Add(new ParseResult(LineType.Empty, string.Empty), 3); // Assert testee.CompleteEntry.MessageString.Should().Be("The msgstr text"); }
public void PuzzleContainer_entryBuilder_should_support_contract_forwarding_in_singleton_types() { var entry = EntryBuilder.For <IFoo>() .Forward <IBar>() .ImplementedBy <TypeWithMultipleContracts>(); var sut = new PuzzleContainer(); sut.Register(entry); var iBar = sut.Resolve <IBar>(); var iFoo = sut.Resolve <IFoo>(); Assert.AreEqual(iBar, iFoo); }
public void Add_WhenEntryHasComment_ShouldCreateEntryWithComment() { // Arrange var testee = new EntryBuilder(); testee.Add(new ParseResult(LineType.Comment, ", the comment text"), 1); testee.Add(new ParseResult(LineType.MessageId, "The msgid text"), 2); testee.Add(new ParseResult(LineType.MessageString, "The msgstr text"), 3); // Act testee.Add(new ParseResult(LineType.Empty, string.Empty), 4); // Assert testee.CompleteEntry.Comments[0].Should().Be(", the comment text"); }
public void Add_WhenEntryHasMsgidPlural_ShouldCreateEntryWithMsgidPlural() { // Arrange var testee = new EntryBuilder(); testee.Add(new ParseResult(LineType.MessageId, "The msgid text"), 1); testee.Add(new ParseResult(LineType.MessageIdPlural, "The msgid_plural text"), 2); testee.Add(new ParseResult(LineType.MessageStringPlural, "The msgstr[0] text"), 3); // Act testee.Add(new ParseResult(LineType.Empty, string.Empty), 4); // Assert testee.CompleteEntry.MessageIdPlural.Should().Be("The msgid_plural text"); }
public void Add_WhenMsgstrOnOneLine_ShouldSetMsgstrLocationToOneLine() { // Arrange var testee = new EntryBuilder(); testee.Add(new ParseResult(LineType.MessageId, "The msgid text"), 1); testee.Add(new ParseResult(LineType.MessageString, "The msgstr text"), 2); // Act testee.Add(new ParseResult(LineType.Empty, string.Empty), 3); // Assert testee.CompleteEntry.MessageStringStart.Should().Be(2); testee.CompleteEntry.MessageStringEnd.Should().Be(2); }
public void PuzzleContainer_entryBuilder_should_support_contract_forwarding_with_instances() { var entry = EntryBuilder.For <IFoo>() .Forward <IBar>() .UsingInstance(new TypeWithMultipleContracts()); var sut = new PuzzleContainer(); sut.Register(entry); var iBar = sut.Resolve <IBar>(); var iFoo = sut.Resolve <IFoo>(); Assert.AreEqual(iBar, iFoo); }
public void Add_WhenMsgidHasPlural_ShouldSetMsgidLocationToAllTheLines() { // Arrange var testee = new EntryBuilder(); testee.Add(new ParseResult(LineType.MessageId, "The msgid text"), 1); testee.Add(new ParseResult(LineType.MessageIdPlural, "The msgid_plural text"), 2); testee.Add(new ParseResult(LineType.MessageString, "The msgstr text"), 3); // Act testee.Add(new ParseResult(LineType.Empty, string.Empty), 4); // Assert testee.CompleteEntry.MessageIdStart.Should().Be(1); testee.CompleteEntry.MessageIdEnd.Should().Be(2); }
public void Add_WhenMsgstrIsOnMultipleLinesStartingWithEmptyString_ShouldTakeAllText() { // Arrange var testee = new EntryBuilder(); testee.Add(new ParseResult(LineType.MessageId, "The msgid text"), 1); testee.Add(new ParseResult(LineType.MessageString, ""), 2); testee.Add(new ParseResult(LineType.Text, "The text"), 3); testee.Add(new ParseResult(LineType.Text, "The second text"), 4); // Act testee.Add(new ParseResult(LineType.Empty, string.Empty), 5); // Assert testee.CompleteEntry.MessageString.Should().Be("The textThe second text"); }
public void Add_WhenEntryStartsWithMsgid_ShouldSetCorrectEntryLocation() { // Arrange var testee = new EntryBuilder(); testee.Add(new ParseResult(LineType.Empty, string.Empty), 1); testee.Add(new ParseResult(LineType.MessageId, "The msgid text"), 2); testee.Add(new ParseResult(LineType.MessageString, "The msgstr text"), 3); // Act testee.Add(new ParseResult(LineType.Empty, string.Empty), 4); // Assert testee.CompleteEntry.Start.Should().Be(2); testee.CompleteEntry.End.Should().Be(3); }
public void PuzzleContainer_entryBuilder_should_support_contract_forwarding_with_factory_method() { var entry = EntryBuilder.For <IFoo>() .Forward <IBar>() .UsingFactory(() => new TypeWithMultipleContracts()) .WithLifestyle(Lifestyle.Singleton); var sut = new PuzzleContainer(); sut.Register(entry); var iBar = sut.Resolve <IBar>(); var iFoo = sut.Resolve <IFoo>(); Assert.AreEqual(iBar, iFoo); }
public void when_registering_POCO_message_handler_facility_should_correctly_subscribe_messages() { var container = new PuzzleContainer(); container.AddFacility <SubscribeToMessageFacility>(); container.Register(EntryBuilder.For <IMessageBroker>().UsingInstance(new MessageBroker(new NullDispatcher()))); container.Register(EntryBuilder.For <IHandleMessage <AMessage> >().ImplementedBy <AMessageHandler>()); var broker = container.Resolve <IMessageBroker>(); var handler = (AMessageHandler)container.Resolve <IHandleMessage <AMessage> >(); broker.Dispatch(this, new AMessage()); Assert.IsTrue(handler.Invoked); }
public void PuzzleContainer_at_dispose_should_dispose_singleton_references() { var entry = EntryBuilder.For <IFoo>() .ImplementedBy <DisposableFoo>() .WithLifestyle(Lifestyle.Singleton); var sut = new PuzzleContainer(); sut.Register(entry); var iFoo = (DisposableFoo)sut.Resolve <IFoo>(); sut.Dispose(); Assert.IsTrue(iFoo.Disposed); }