コード例 #1
0
        public void AddNothingTest()
        {
            var entityType = MockUtilities.CreateEntityMock(typeof(int), "Value").Object;
            var editor     = new PropertyAttributeEditor
            {
                TypeNameWriter = new TypeNameWriter(false),
                EntityType     = entityType,
                AllElements    = new List <IWritableElement>
                {
                    new InterfaceElement(typeof(IAttributeTaggedEntityConventionDateTimeProperty))
                }
            };

            var edited = editor.EditEntity(@"using System;

public partial class Entity
{
        public int Value { get; set; }
}");

            var expected = @"using System;

public partial class Entity
{
        public int Value { get; set; }
}";

            Assert.Equal(expected, edited);
        }
コード例 #2
0
        public void AddSingleUsingStatement()
        {
            var entityType = MockUtilities.CreateEntityMock(typeof(int?), "Value").Object;
            var editor     = new NamespaceEditor
            {
                EntityType  = MockUtilities.CreateEntityMock().Object,
                AllElements = new List <IWritableElement>
                {
                    new PropertyAttributeElement
                    {
                        Attribute = typeof(DummyAttribute)
                    }
                }
            };

            var edited = editor.EditEntity(@"using System;

namespace EntityScaffolding.Tests.Models
{
    Class
}");

            var expected = $@"using System;
using {typeof(DummyAttribute).Namespace};

namespace EntityScaffolding.Tests.Models
{{
    Class
}}";

            Assert.Equal(expected, edited);
            Assert.False(editor.TypeNameWriter.RequiresFullyQualifiedNames);
        }
        public void ApplyingInterfaceWriterSameNamespaceTest()
        {
            var helper     = new Mock <ICSharpHelper>();
            var entityType = MockUtilities.CreateEntityMock(typeof(string), "CustomProperty");

            var generator = new ConventionEntityTypeGeneratorMock(helper.Object,
                                                                  @"public partial class Entity
    {
        public string CustomProperty { get; set; }
    }");

            var entity = generator.WriteCode(entityType.Object, "EntityScaffolding.Tests.DummyClasses.Models", false);

            var expected = @"using System;
using System.Collections.Generic;

namespace EntityScaffolding.Tests.DummyClasses.Models
{
    public partial class Entity : IAttributeTaggedEntityConventionStringProperty
    {
        public string CustomProperty { get; set; }
    }
}
";

            Assert.Equal(expected, entity);
        }
コード例 #4
0
        public void DoNotAddUsingWhenInNameSpaceUnitTest()
        {
            var entityType = MockUtilities.CreateEntityMock(typeof(int?), "Value").Object;
            var editor     = new NamespaceEditor
            {
                EntityType  = MockUtilities.CreateEntityMock().Object,
                AllElements = new List <IWritableElement>
                {
                    new InterfaceElement(typeof(IAttributeTaggedEntityConventionDateTimeProperty))
                }
            };

            var edited = editor.EditEntity(@"using System;

namespace EntityScaffolding.Tests.DummyClasses.Models
{
    Class
}");

            var expected = $@"using System;

namespace EntityScaffolding.Tests.DummyClasses.Models
{{
    Class
}}";

            Assert.Equal(expected, edited);
            Assert.False(editor.TypeNameWriter.RequiresFullyQualifiedNames);
        }
コード例 #5
0
        public void AddMultipleInterfaceNotFullyQualifiedTest()
        {
            var editor = new InterfaceEditor
            {
                TypeNameWriter = new TypeNameWriter(false),
                EntityType     = MockUtilities.CreateEntityMock().Object,
                AllElements    = new List <IWritableElement>
                {
                    new InterfaceElement(typeof(IAttributeTaggedEntityConventionDateTimeProperty)),
                    new InterfaceElement(typeof(IAttributeTaggedEntityConventionNullableIntProperty))
                }
            };

            var edited = editor.EditEntity(@"using System;

public partial class Entity
{
}");

            var expected = @"using System;

public partial class Entity : IAttributeTaggedEntityConventionDateTimeProperty, IAttributeTaggedEntityConventionNullableIntProperty
{
}";

            Assert.Equal(expected, edited);
        }
コード例 #6
0
 public override void Initialize(LinkedNavigationEvent linkedNavigationEvent)
 {
     Key          = linkedNavigationEvent.Key;
     ResponseType = MockUtilities.GetResponseFromGUID(Key);
     Parameters   = MockUtilities.GetParametersFromGUID(Key);
     TradeDate    = MockUtilities.GetTradeDateFromGUID(Key);
 }
コード例 #7
0
        public void AddNothingTest()
        {
            var editor = new InterfaceEditor
            {
                TypeNameWriter = new TypeNameWriter(false),
                EntityType     = MockUtilities.CreateEntityMock().Object,
                AllElements    = new List <IWritableElement>
                {
                    new PropertyAttributeElement()
                }
            };

            var edited = editor.EditEntity(@"using System;

public partial class Entity
{
}");

            var expected = @"using System;

public partial class Entity
{
}";

            Assert.Equal(expected, edited);
        }
コード例 #8
0
        public void DoNotAddUsingWhenConflictingNamesUnitTest()
        {
            var entityType = MockUtilities.CreateEntityMock(typeof(int?), "Value").Object;
            var editor     = new NamespaceEditor
            {
                EntityType  = MockUtilities.CreateEntityMock().Object,
                AllElements = new List <IWritableElement>
                {
                    new InterfaceElement(typeof(EntityScaffolding.Tests.DummyClasses.MoreAgain.IConflictingName)),
                    new InterfaceElement(typeof(EntityScaffolding.Tests.DummyClasses.More.IConflictingName))
                }
            };

            var edited = editor.EditEntity(@"using System;

namespace EntityScaffolding.Tests.Models
{
    Class
}");

            var expected = $@"using System;

namespace EntityScaffolding.Tests.Models
{{
    Class
}}";

            Assert.Equal(expected, edited);
            Assert.True(editor.TypeNameWriter.RequiresFullyQualifiedNames);
        }
コード例 #9
0
        public void TestGetAllCampaignsMockAndCallServer()
        {
            ServiceSignature mockSignature = MockUtilities.RegisterMockService(user,
                                                                               AdWordsService.v201605.CampaignService, typeof(MockCampaignServiceEx));

            CampaignService campaignService = (CampaignService)user.GetService(mockSignature);

            Assert.That(campaignService is MockCampaignServiceEx);

            Campaign campaign = new Campaign();

            campaign.name = "Interplanetary Cruise #" + new TestUtils().GetTimeStamp();

            // Set the test campaign to PAUSED when creating it to prevent the ads from serving.
            campaign.status = CampaignStatus.PAUSED;

            campaign.biddingStrategyConfiguration = new BiddingStrategyConfiguration();
            campaign.biddingStrategyConfiguration.biddingStrategyType = BiddingStrategyType.MANUAL_CPC;

            Budget budget = new Budget();

            budget.budgetId = budgetId;

            campaign.budget = budget;

            campaign.advertisingChannelType = AdvertisingChannelType.SEARCH;

            // Set the campaign network options to GoogleSearch and SearchNetwork
            // only. Set ContentNetwork, PartnerSearchNetwork and ContentContextual
            // to false.
            campaign.networkSetting = new NetworkSetting()
            {
                targetGoogleSearch         = true,
                targetSearchNetwork        = true,
                targetContentNetwork       = false,
                targetPartnerSearchNetwork = false
            };

            // Create operations.
            CampaignOperation operation = new CampaignOperation();

            operation.@operator = Operator.ADD;
            operation.operand   = campaign;

            CampaignReturnValue retVal = null;

            Assert.DoesNotThrow(delegate() {
                retVal = campaignService.mutate((new CampaignOperation[] { operation }));
            });

            Assert.NotNull(retVal);
            Assert.NotNull(retVal.value);
            Assert.AreEqual(retVal.value.Length, 1);
            Assert.AreEqual(retVal.value[0].name, campaign.name);
            Assert.AreNotEqual(retVal.value[0].id, 0);
            Assert.True((campaignService as MockCampaignServiceEx).MutateCalled);
        }
コード例 #10
0
        public void TestGetAllCampaignsMockAndCallServer()
        {
            MockUtilities.RegisterMockService(user, AdWordsService.v201406.CampaignService,
                                              typeof(MockCampaignServiceEx));
            CampaignService campaignService = (CampaignService)user.GetService(
                AdWordsService.v201406.CampaignService);

            Assert.That(campaignService is MockCampaignServiceEx);

            Campaign campaign = new Campaign();

            campaign.name   = "Interplanetary Cruise #" + new TestUtils().GetTimeStamp();
            campaign.status = CampaignStatus.PAUSED;

            BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();

            biddingConfig.biddingStrategyType     = BiddingStrategyType.MANUAL_CPC;
            campaign.biddingStrategyConfiguration = biddingConfig;

            Budget budget = new Budget();

            budget.period             = BudgetBudgetPeriod.DAILY;
            budget.deliveryMethod     = BudgetBudgetDeliveryMethod.STANDARD;
            budget.amount             = new Money();
            budget.amount.microAmount = 50000000;

            campaign.budget = budget;

            // Set the campaign network options to GoogleSearch and SearchNetwork
            // only. Set ContentNetwork, PartnerSearchNetwork and ContentContextual
            // to false.
            campaign.networkSetting = new NetworkSetting();
            campaign.networkSetting.targetGoogleSearch         = true;
            campaign.networkSetting.targetSearchNetwork        = true;
            campaign.networkSetting.targetContentNetwork       = false;
            campaign.networkSetting.targetPartnerSearchNetwork = false;

            // Create operations.
            CampaignOperation operation = new CampaignOperation();

            operation.@operator = Operator.ADD;
            operation.operand   = campaign;

            CampaignReturnValue retVal = null;

            Assert.DoesNotThrow(delegate() {
                retVal = campaignService.mutate((new CampaignOperation[] { operation }));
            });

            Assert.NotNull(retVal);
            Assert.NotNull(retVal.value);
            Assert.AreEqual(retVal.value.Length, 1);
            Assert.AreEqual(retVal.value[0].name, campaign.name);
            Assert.AreNotEqual(retVal.value[0].id, 0);
            Assert.True((campaignService as MockCampaignServiceEx).MutateCalled);
        }
コード例 #11
0
        public void CustomInterfaceConventionPickedUppedAndMatchesEntity
            (Type propertyType, string propertyName, Type conventionType)
        {
            var entityMock = MockUtilities.CreateEntityMock(propertyType, propertyName);

            var configuration = new ConventionConfiguration();

            var elements = configuration.ConventionMatchers.FindApplicableConventions(entityMock.Object).ToList();

            Assert.Single(elements);

            Assert.Equal(conventionType, (elements.Single() as InterfaceElement)?.InterfaceType);
        }
コード例 #12
0
        public void ConventionPickedUppedAndMatchesEntity()
        {
            var entityMock = MockUtilities.CreateEntityMock(typeof(string), "Something");

            MockEntityInterfaceConventionMatcher.AppliesToEntityFunction = e =>
                                                                           e == entityMock.Object ? new InterfaceElement(typeof(IDummyInterface1)) : null;

            var configuration = new ConventionConfiguration();

            var elements = configuration.ConventionMatchers.FindApplicableConventions(entityMock.Object).ToList();

            Assert.Single(elements);

            Assert.Equal(typeof(IDummyInterface1), (elements.Single() as InterfaceElement)?.InterfaceType);
        }
コード例 #13
0
        public void LaunchBacktest()
        {
            var viewModel     = IoC.Get <BacktestStatusViewModel>();
            var backtestGroup = MockUtilities.GenerateBacktestGroupRecords(1).First();

            viewModel.Initialize(backtestGroup, 4);

            IoC.Get <IWindowManager>().ShowWindow(viewModel);

            var requestEvent = new BacktestRequestEvent();

            requestEvent.ActionType      = ServiceAction.Run;
            requestEvent.Response        = new DarkLightResponse();
            requestEvent.Response.Key    = backtestGroup.GUID;
            requestEvent.HistDataService = IoC.Get <IHistDataService>();
            IoC.Get <IEventBroker>().Publish(requestEvent);
        }
コード例 #14
0
        public void AddMultipleInterfaceNotFullyQualifiedTest()
        {
            var entityType = MockUtilities.CreateEntityMock(typeof(int), "Value").Object;
            var editor     = new PropertyAttributeEditor
            {
                TypeNameWriter = new TypeNameWriter(false),
                EntityType     = entityType,
                AllElements    = new List <IWritableElement>
                {
                    new PropertyAttributeElement
                    {
                        Attribute       = typeof(DummyAttribute),
                        AttributeValues = new List <string> {
                            "1001", "\"string\""
                        },
                        Property = entityType.GetProperties().Single()
                    },
                    new PropertyAttributeElement
                    {
                        Attribute = typeof(Dummy2Attribute),
                        Property  = entityType.GetProperties().Single()
                    }
                }
            };

            var edited = editor.EditEntity(@"using System;

public partial class Entity
{
        public int Value { get; set; }
}");

            var expected = @"using System;

public partial class Entity
{
        
        [Dummy(1001, ""string"")]
        [Dummy2]
        public int Value { get; set; }
}";

            Assert.Equal(expected, edited);
        }
        public void ApplyingPropertyAttributeParameterWriterTest()
        {
            var helper     = new Mock <ICSharpHelper>();
            var entityType = MockUtilities.CreateEntityMock(typeof(string), "ApplyHere");

            MockEntityPropertyAttributeConventionMatcher.AppliesToEntityFunction = e =>
                                                                                   e == entityType.Object ? new PropertyAttributeElement
            {
                Attribute       = typeof(DummyAttribute),
                Property        = entityType.Object.GetProperties().Single(),
                AttributeValues = new List <string> {
                    "1101"
                }
            } : null;

            var generator = new ConventionEntityTypeGeneratorMock(helper.Object,
                                                                  @"public partial class Entity
    {
        public string ApplyHere { get; set; }
    }");

            var entity = generator.WriteCode(entityType.Object, "EntityScaffolding.Tests.DummyClasses.Models", false);

            var expected = @"using System;
using System.Collections.Generic;

namespace EntityScaffolding.Tests.DummyClasses.Models
{
    public partial class Entity
    {
        
        [Dummy(1101)]
        public string ApplyHere { get; set; }
    }
}
";

            Assert.Equal(expected, entity);
        }
コード例 #16
0
        public void TestGetAllCampaignsMockOnly()
        {
            ServiceSignature mockSignature = MockUtilities.RegisterMockService(user,
                                                                               AdWordsService.v201605.CampaignService, typeof(MockCampaignService));

            CampaignService campaignService = (CampaignService)user.GetService(mockSignature);

            Assert.That(campaignService is MockCampaignService);

            // Create a selector.
            Selector selector = new Selector();

            selector.fields = new string[] { "Id", "Name", "Status" };

            CampaignPage page = null;

            Assert.DoesNotThrow(delegate() {
                page = campaignService.get(selector);
            });

            Assert.IsNull(page);
            Assert.True((campaignService as MockCampaignService).GetCalled);
        }
コード例 #17
0
 public void SendMessage()
 {
     if (SelectedEventType == EventType.LinkedNavigation)
     {
         IoC.Get <IEventBroker>().Publish(new LinkedNavigationEvent
         {
             NavigationAction = SelectedNavigationAction,
             ColorGroup       = SelectedColorGroup,
             Destination      = SelectedNavigationDestination,
             Key = TestKey,
         });
     }
     else if (SelectedEventType == EventType.Trade)
     {
         IoC.Get <IEventBroker>().Publish(new TradeEvent
         {
             Key      = TestKey,
             Fill     = MockUtilities.GenerateFills(TestKey, 1)[0],
             Order    = MockUtilities.GenerateOrders(TestKey, 1)[0],
             Position = MockUtilities.GeneratePositions(TestKey, 1)[0],
             Tick     = MockUtilities.GenerateTicks(TestKey, 1)[0],
         });
     }
 }
コード例 #18
0
 public void AddOrder()
 {
     Orders.Add(MockUtilities.GenerateOrders("backtestidToImplement", 1)[0]);
 }
コード例 #19
0
 public void AddPosition()
 {
     Positions.Add(MockUtilities.GeneratePositions("backtestidToImplement", 1)[0]);
 }
コード例 #20
0
 public void AddTick()
 {
     Ticks.Add(MockUtilities.GenerateTicks("backtestidToImplement", 1)[0]);
 }
コード例 #21
0
 public void AddFill(DarkLightFill fill)
 {
     Fills.Add(MockUtilities.GenerateFills("backtestidToImplement", 1)[0]);
 }