CreateEvent() public method

public CreateEvent ( string someCondition ) : IEvent,
someCondition string
return IEvent,
コード例 #1
0
    /**
     * TODO will be called every turn regardless of weather it is moved or not in order to count turns in air
     */
    public override void MoveAsPlanned(Vector3 newPos)
    {
        TurnsNotLanded++;
        if (TurnsNotLanded >= MaxTurnsAirborne)
        {
            // Create a DieEvent
            object[] arguments = new object[1];
            arguments[0] = (this.gameObject.GetComponent <IdentityController>()).GetGuid();
            EventManager.Instance.AddEvent(EventFactory.CreateEvent(GEventType.DieEvent, arguments));
        }
        else
        {
            // Modify the CurrentRange by the distance traveled
            CurrentRange -= Vector3.Distance(newPos, this.gameObject.transform.position);

            // If the unit has moved outside of its current range
            if (CurrentRange < 0)
            {
                // Create a DieEvent
                object[] arguments = new object[1];
                arguments[0] = (this.gameObject.GetComponent <IdentityController>()).GetGuid();
                EventManager.Instance.AddEvent(EventFactory.CreateEvent(GEventType.DieEvent, arguments));
            }
            else
            {
                base.MoveAsPlanned(newPos);
            }
        }
    }
コード例 #2
0
        public void TestThatEventTypeIsProperlyUsed()
        {
            var eventType = new EventType("type");
            var eventObj  = EventFactory.CreateEvent(eventType, "content");

            Assert.AreEqual("content", eventObj.Content);
            Assert.AreEqual(eventType.Value, eventObj.Type.Value);
        }
コード例 #3
0
    /**
     * Waits for the end of the frame, then throws a startofturn event.
     */
    public static void ThrowStartOfTurnEvent()
    {
        //yield return new WaitForEndOfFrame();

        object[] args = { TurnCount };

        EventManager.Instance.AddEvent(EventFactory.CreateEvent(GEventType.StartOfTurnEvent, args));
    }
コード例 #4
0
    /**
     * Removes the user from the game
     *
     * @param team
     *      The team the user is on.
     * @param username
     *      The username of the user to be removed.
     */
    public static void RemoveUser(int team, string username)
    {
        object[] arguments = new object[2];
        arguments[0] = username;
        arguments[1] = team;

        EventManager.Instance.AddEvent(EventFactory.CreateEvent(GEventType.PlayerLeaveEvent, arguments));
    }
コード例 #5
0
        public void TestThatEventTypeIsProperlyInterpreted()
        {
            var attributes = new Dictionary <string, object> {
                { "__type", "sometype" }
            };
            var eventObj = EventFactory.CreateEvent("content", attributes);

            Assert.AreEqual("sometype", eventObj.Type.Value);
        }
コード例 #6
0
        public void TestThatEventCanBeCreatedWithContentAndAttributes()
        {
            var attributes = new Dictionary <string, object> {
                { "test", "value" }
            };
            var eventObj = EventFactory.CreateEvent("content", attributes);

            Assert.AreEqual("content", eventObj.Content);
            Assert.AreEqual("value", eventObj.Attributes["test"]);
        }
コード例 #7
0
        public void CreateEvent_Providers_ThrowsIfAlreadyExists()
        {
            var factory = new EventFactory(new MethodFactory(new RelatedMethodFinder()));

            Func <MethodBodyCreationContext, Expression> bodyProvider = ctx => Expression.Empty();
            var event_ = _mutableType.AddEvent("Event", typeof(Action), addBodyProvider: bodyProvider, removeBodyProvider: bodyProvider);

            Assert.That(
                () => factory.CreateEvent(_mutableType, "OtherName", event_.EventHandlerType, 0, bodyProvider, bodyProvider, null),
                Throws.Nothing);

            Assert.That(
                () => factory.CreateEvent(_mutableType, event_.Name, typeof(Action <int>), 0, bodyProvider, bodyProvider, null),
                Throws.Nothing);

            Assert.That(
                () => factory.CreateEvent(_mutableType, event_.Name, event_.EventHandlerType, 0, bodyProvider, bodyProvider, null),
                Throws.InvalidOperationException.With.Message.EqualTo("Event with equal name and signature already exists."));
        }
コード例 #8
0
        private IEvent SetUpEvent()
        {
            IEventFactory       _eventFactory = new EventFactory();
            List <IInvitation>  invitations   = SetUpInvitations();
            List <IParticipant> participants  = SetUpParticipants();

            Guid   testGuid = Guid.NewGuid();
            IEvent @event   = _eventFactory.CreateEvent(testGuid, "Födelsedagsfest", "En rolig fest för att fira en födelsedag", DateTime.Now, invitations, participants);

            return(@event);
        }
コード例 #9
0
        public void CreateEventTestCallArrive()
        {
            EventFactory target     = new EventFactory();
            EEventType   eventType  = EEventType.CallArrive;
            DateTime     eventTime  = new DateTime();
            Call         entity     = null;
            string       eventTypeS = "Arrive at Call Centre";
            Event        actual;

            actual = target.CreateEvent(eventType, eventTime, entity);
            Assert.AreEqual(eventTypeS, actual.EventType);
        }
コード例 #10
0
        public void CreateEventTestCompleteService()
        {
            EventFactory target     = new EventFactory();
            EEventType   eventType  = EEventType.CompletedService;
            DateTime     eventTime  = new DateTime();
            Call         entity     = null;
            string       eventTypeS = "Completed Service";
            Event        actual;

            actual = target.CreateEvent(eventType, eventTime, entity);
            Assert.AreEqual(eventTypeS, actual.EventType);
        }
コード例 #11
0
        public void CreateEventTestEndReplication()
        {
            EventFactory target     = new EventFactory();
            EEventType   eventType  = EEventType.EndReplication;
            DateTime     eventTime  = new DateTime();
            Call         entity     = null;
            string       eventTypeS = "End Replication";
            Event        actual;

            actual = target.CreateEvent(eventType, eventTime, entity);
            Assert.AreEqual(eventTypeS, actual.EventType);
        }
コード例 #12
0
        public void CreateEventTestSwitchComplete()
        {
            EventFactory target     = new EventFactory();
            EEventType   eventType  = EEventType.SwitchCompleted;
            DateTime     eventTime  = new DateTime();
            Call         entity     = null;
            string       eventTypeS = "Completed Switch Processing";
            Event        actual;

            actual = target.CreateEvent(eventType, eventTime, entity);
            Assert.AreEqual(eventTypeS, actual.EventType);
        }
コード例 #13
0
        public Event CreateEventViaFactory(long eventTypeID)
        {
            EventFactory eventFactory = new EventFactory(db);

            var type        = db.EventTypes.Where(x => x.EventTypeID.Equals(eventTypeID)).First();
            var returnEvent = eventFactory.CreateEvent(type);

            returnEvent.EventType = type;


            return(returnEvent);
        }
コード例 #14
0
        public void RehydrateAggregateFailsIfEventAggregateIdMismatch()
        {
            var aggregateId  = Guid.NewGuid().ToString();
            var locationName = "location1";
            var item         = new StockItem("item1", "1");

            var contextMap = new BoundedContextModel().WithAssemblyContaining <Location>();

            var aggregateRoot    = new Location();
            var aggregateAdapter = AggregateAdapterFactory.Default.CreateAggregate(contextMap, aggregateRoot).WithId(aggregateId);

            var eventAdapterFactory = new EventFactory();

            var aggregateEventHistory = new List <IEvent>();

            aggregateEventHistory.Add(eventAdapterFactory.CreateEvent <Location, LocationCreated>(aggregateId, 1, string.Empty, string.Empty, new LocationCreated(locationName, string.Empty)));
            aggregateEventHistory.Add(eventAdapterFactory.CreateEvent <Location, AdjustedIn>(aggregateId, 2, string.Empty, string.Empty, new AdjustedIn($"adjustment_{Guid.NewGuid()}", locationName, item)));
            aggregateEventHistory.Add(eventAdapterFactory.CreateEvent <Location, MovedOut>(Guid.NewGuid().ToString(), 3, string.Empty, string.Empty, new MovedOut($"movement_{Guid.NewGuid()}", locationName, item, "toLocationName")));

            Assert.ThrowsException <ArgumentException>(() => aggregateAdapter.Rehydrate(aggregateEventHistory));
        }
コード例 #15
0
    /**
     * Removes a unit from this Container, changes state of unit to unembarked, and moves it to the given position.
     * @param unit
     *      The unit to be removed
     */
    public void Launch(String unit, Vector3 pos)
    {
        float PercentHealth = ((HealthController)this.gameObject.GetComponent("HealthController")).GetCurrentPercentHealth();

        //TODO: determine if we want the health restriction for just aircraft or all contained units
        if (PercentHealth >= GlobalSettings.GetHealthThresholdForNoDetectors())
        {
            GameObject u = GuidList.GetGameObject(unit);
            if (Vector3.Distance(pos, this.transform.position) < u.GetComponent <MoverController>().MoveRange)
            {
                // throw the UnitUnEmbarksEvent event
                object[] arguments = new object[3];
                arguments[0] = unit;
                arguments[1] = new Point((int)pos.x, (int)pos.y, (int)pos.z);
                arguments[2] = this.gameObject.GetComponent <IdentityController>().GetGuid();

                EventManager.Instance.AddEvent(EventFactory.CreateEvent(GEventType.UnitUnEmbarksEvent, arguments, 1));
            }
        }
    }
コード例 #16
0
        public async void GetLocationEvent()
        {
            //Create 1 location using the locationFactory
            Location locationTest = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            //Create 2 Events using the eventFactory
            Event event1 = await this.eventRepository.CreateAsync(EventFactory.CreateEvent(1, 1, 1));

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            ObjectResult result = (ObjectResult)await eventController.LocationGetEvent(request, locationTest.Id, event1.Id);

            EventResponse eventResult = (EventResponse)result.Value;

            // Status code should return 200 OK
            Assert.Equal(200, result.StatusCode);

            //Check if organisorId is the same for both
            //Assert.Equal(1, eventResult.Organisor);
        }
コード例 #17
0
    /**
     * Allows the unit to take damage. Checks if the unit should die after
     * damage is dealt.
     *
     * @param damage
     *      The amount of damage the unit will take
     */
    public void DamageUnit(float damage, string causingTeam)
    {
        // Deal damage to the unit
        SetCurrentHealth(GetCurrentHealth() - damage);

        // Check if the unit shoud die
        if (GetCurrentHealth() <= 0 && !Dying)
        {
            // If the unit should die

            // throws the event for death
            object[] arguments = new object[5];
            arguments [0] = (this.gameObject.GetComponent <IdentityController> ()).GetGuid();
            arguments [1] = causingTeam;
            arguments [2] = this.gameObject.GetComponent <IdentityController> ().GetName();
            arguments [3] = Team.Teams[this.gameObject.GetComponent <IdentityController> ().GetTeam()].GetTeamName();
            arguments [4] = this.gameObject.GetComponent <IdentityController> ().GetFullName();

            EventManager.Instance.AddEvent(EventFactory.CreateEvent(GEventType.DieEvent, arguments));
            Dying = true;
        }
    }
コード例 #18
0
    /*
     * Sets the container to contain this unit, and changes state, if the unit is within range of the target container.
     *
     * @param parent
     *      The container that will contain this unit.
     */
    public void Embark(String parent)
    {
        //Debug.Log ("HERE:" + parent);

        GameObject g = GuidList.GetGameObject(parent);

        if (g.GetComponent <ContainerController> ().GetInUse())
        {
            if (Vector3.Distance(this.transform.position, GuidList.GetGameObject(parent).transform.position) < this.gameObject.GetComponent <MoverController> ().MoveRange)
            {
                // throw the UnitEmbarksEvent event
                object[] arguments = new object[2];
                arguments [0] = this.gameObject.GetComponent <IdentityController> ().GetGuid();
                arguments [1] = GuidList.GetGameObject(parent).GetComponent <IdentityController> ().GetGuid();
                Parent        = parent;
                //Debug.Log ("HEREERE: "  + Parent);
                EventManager.Instance.AddEvent(EventFactory.CreateEvent(GEventType.UnitEmbarksEvent, arguments, 1));
            }
            gameObject.GetComponent <CircleCollider2D> ().enabled = false;
            gameObject.GetComponent <SpriteRenderer> ().enabled   = false;
        }
    }
コード例 #19
0
    /**
     * Creates a new user and adds them to the specified team.
     *
     * @param permissionLevel
     *      The permission level of the user
     * @param branch
     *      The branch of the military this user is playing for
     * @param team
     *      The team the user will be added to
     * @param username
     *      The name the user wants to use
     * @param unitGuid
     *      The string form of the Guid that represents the object.
     *
     * @return
     *      True	The user was added
     *      False	The was not created because the username already exists
     */
    public static bool AddNewUser(PermissionLevel permissionLevel, MilitaryBranch branch, int team, string username, string unitGuid)
    {
        // Check if the username is used by that team
        if (Team.UsernameInUse(username))
        {
            // If the username is already in use
            //Debug.Log ("Username in use");
            // Return false because the user cannot be added.
            return(false);
        }

        object[] arguments = new object[5];
        arguments[0] = permissionLevel;
        arguments[1] = branch;
        arguments[2] = team;
        arguments[3] = username;
        arguments[4] = unitGuid;

        GEvent e = EventFactory.CreateEvent(GEventType.PlayerJoinEvent, arguments);

        EventManager.Instance.AddEvent(e);
        //Debug.Log ("User Join event raised");
        return(true);
    }
コード例 #20
0
        static Mission ReadFile(string filePath)
        {
            var mission = new Mission();

            var fileStream   = new FileStream(filePath, FileMode.Open);
            var binaryReader = new BinaryReader(fileStream);

            // 1. House Tech level
            binaryReader.Read(mission.HouseTechLevel, 0, mission.HouseTechLevel.Length);

            // 2. Starting money
            for (var i = 0; i < mission.StartingMoney.Length; i++)
            {
                mission.StartingMoney[i] = binaryReader.ReadInt32();
            }

            // 3. Unknown region of 40 bytes
            binaryReader.Read(mission.UnknownRegion1, 0, mission.UnknownRegion1.Length);

            // 4. House index allocation
            binaryReader.Read(mission.HouseIndexAllocation, 0, mission.HouseIndexAllocation.Length);

            // 5. AI Section
            for (var i = 0; i < mission.AISection.Length; i++)
            {
                mission.AISection[i] = new AISection(binaryReader.ReadBytes(AISection.ByteCount));
            }

            // 6. Diplomacy
            for (var i = 0; i < mission.Diplomacy.Length; i++)
            {
                mission.Diplomacy[i] = new DiplomacyRow(binaryReader.ReadBytes(DiplomacyRow.ByteCount));
            }

            // 7. Events
            for (var i = 0; i < mission.Events.Length; i++)
            {
                mission.Events[i] = EventFactory.CreateEvent(binaryReader.ReadBytes(Event.ByteCount));
            }

            // 8. Conditions
            for (var i = 0; i < mission.Conditions.Length; i++)
            {
                mission.Conditions[i] = ConditionFactory.CreateCondition(binaryReader.ReadBytes(Condition.ByteCount));
            }

            // 9. Tileset image name
            binaryReader.Read(mission.TilesetImageName, 0, mission.TilesetImageName.Length);

            // 10. Tileset data file name
            binaryReader.Read(mission.TilesetDataName, 0, mission.TilesetDataName.Length);

            // 11. Active events count
            mission.EventCount = binaryReader.ReadByte();

            // 12. Active conditions count
            mission.ConditionCount = binaryReader.ReadByte();

            // 13. Time limit
            mission.TimeLimit = binaryReader.ReadInt32();

            // 14. Unknown region of remaining bytes
            binaryReader.Read(mission.UnknownRegion2, 0, mission.UnknownRegion2.Length);

            binaryReader.Close();
            fileStream.Close();

            return(mission);
        }
コード例 #21
0
        public void CreateEvent_Providers()
        {
            var name = "Event";
            var accessorAttributes = (MethodAttributes)7;
            var handlerType        = typeof(SomeDelegate);
            var handlerReturnType  = typeof(string);
            Func <MethodBodyCreationContext, Expression> addBodyProvider    = ctx => null;
            Func <MethodBodyCreationContext, Expression> removeBodyProvider = ctx => null;
            Func <MethodBodyCreationContext, Expression> raiseBodyProvider  = ctx => null;
            var fakeAddMethod    = MutableMethodInfoObjectMother.Create(parameters: new[] { ParameterDeclarationObjectMother.Create(handlerType) });
            var fakeRemoveMethod = MutableMethodInfoObjectMother.Create(parameters: new[] { ParameterDeclarationObjectMother.Create(handlerType) });
            var fakeRaiseMethod  = MutableMethodInfoObjectMother.Create(
                returnType: typeof(string),
                parameters: new[]
            {
                ParameterDeclarationObjectMother.Create(typeof(object)),
                ParameterDeclarationObjectMother.Create(typeof(int).MakeByRefType())
            });

            _methodFactoryMock
            .Expect(
                mock =>
                mock.CreateMethod(
                    Arg.Is(_mutableType),
                    Arg.Is("add_Event"),
                    Arg.Is(accessorAttributes | MethodAttributes.SpecialName),
                    Arg.Is(GenericParameterDeclaration.None),
                    Arg <Func <GenericParameterContext, Type> > .Is.Anything,
                    Arg <Func <GenericParameterContext, IEnumerable <ParameterDeclaration> > > .Is.Anything,
                    Arg.Is(addBodyProvider)))
            .WhenCalled(
                mi =>
            {
                var returnType = mi.Arguments[4].As <Func <GenericParameterContext, Type> >() (null);
                Assert.That(returnType, Is.SameAs(typeof(void)));

                var parameter = mi.Arguments[5].As <Func <GenericParameterContext, IEnumerable <ParameterDeclaration> > >() (null).Single();
                Assert.That(parameter.Type, Is.SameAs(handlerType));
                Assert.That(parameter.Name, Is.EqualTo("handler"));
            })
            .Return(fakeAddMethod);
            _methodFactoryMock
            .Expect(
                mock =>
                mock.CreateMethod(
                    Arg.Is(_mutableType),
                    Arg.Is("remove_Event"),
                    Arg.Is(accessorAttributes | MethodAttributes.SpecialName),
                    Arg.Is(GenericParameterDeclaration.None),
                    Arg <Func <GenericParameterContext, Type> > .Is.Anything,
                    Arg <Func <GenericParameterContext, IEnumerable <ParameterDeclaration> > > .Is.Anything,
                    Arg.Is(removeBodyProvider)))
            .WhenCalled(
                mi =>
            {
                var returnType = mi.Arguments[4].As <Func <GenericParameterContext, Type> >() (null);
                Assert.That(returnType, Is.SameAs(typeof(void)));

                var parameter = mi.Arguments[5].As <Func <GenericParameterContext, IEnumerable <ParameterDeclaration> > >() (null).Single();
                Assert.That(parameter.Type, Is.SameAs(handlerType));
                Assert.That(parameter.Name, Is.EqualTo("handler"));
            })
            .Return(fakeRemoveMethod);
            _methodFactoryMock
            .Expect(
                mock =>
                mock.CreateMethod(
                    Arg.Is(_mutableType),
                    Arg.Is("raise_Event"),
                    Arg.Is(accessorAttributes | MethodAttributes.SpecialName),
                    Arg.Is(GenericParameterDeclaration.None),
                    Arg <Func <GenericParameterContext, Type> > .Is.Anything,
                    Arg <Func <GenericParameterContext, IEnumerable <ParameterDeclaration> > > .Is.Anything,
                    Arg.Is(raiseBodyProvider)))
            .WhenCalled(
                mi =>
            {
                var returnType = mi.Arguments[4].As <Func <GenericParameterContext, Type> >() (null);
                Assert.That(returnType, Is.SameAs(handlerReturnType));

                var parameters = mi.Arguments[5].As <Func <GenericParameterContext, IEnumerable <ParameterDeclaration> > >() (null).ToList();
                Assert.That(parameters[0].Type, Is.SameAs(typeof(object)));
                Assert.That(parameters[0].Name, Is.EqualTo("sender"));
                Assert.That(parameters[0].Attributes, Is.EqualTo(ParameterAttributes.None));
                Assert.That(parameters[1].Type, Is.SameAs(typeof(int).MakeByRefType()));
                Assert.That(parameters[1].Name, Is.EqualTo("outParam"));
                Assert.That(parameters[1].Attributes, Is.EqualTo(ParameterAttributes.Out));
            })
            .Return(fakeRaiseMethod);

            var result = _factory.CreateEvent(_mutableType, name, handlerType, accessorAttributes, addBodyProvider, removeBodyProvider, raiseBodyProvider);

            _methodFactoryMock.VerifyAllExpectations();
            Assert.That(result.DeclaringType, Is.SameAs(_mutableType));
            Assert.That(result.Name, Is.EqualTo(name));
            Assert.That(result.Attributes, Is.EqualTo(EventAttributes.None));
            Assert.That(result.EventHandlerType, Is.SameAs(handlerType));
            Assert.That(result.MutableAddMethod, Is.SameAs(fakeAddMethod));
            Assert.That(result.MutableRemoveMethod, Is.SameAs(fakeRemoveMethod));
            Assert.That(result.MutableRaiseMethod, Is.SameAs(fakeRaiseMethod));
        }
コード例 #22
0
        public void CreateEvent_Providers()
        {
            var name = "Event";
            var accessorAttributes = (MethodAttributes)7;
            var handlerType        = typeof(SomeDelegate);
            var handlerReturnType  = typeof(string);
            Func <MethodBodyCreationContext, Expression> addBodyProvider    = ctx => null;
            Func <MethodBodyCreationContext, Expression> removeBodyProvider = ctx => null;
            Func <MethodBodyCreationContext, Expression> raiseBodyProvider  = ctx => null;
            var fakeAddMethod    = MutableMethodInfoObjectMother.Create(parameters: new[] { ParameterDeclarationObjectMother.Create(handlerType) });
            var fakeRemoveMethod = MutableMethodInfoObjectMother.Create(parameters: new[] { ParameterDeclarationObjectMother.Create(handlerType) });
            var fakeRaiseMethod  = MutableMethodInfoObjectMother.Create(
                returnType: typeof(string),
                parameters: new[]
            {
                ParameterDeclarationObjectMother.Create(typeof(object)),
                ParameterDeclarationObjectMother.Create(typeof(int).MakeByRefType())
            });

            _methodFactoryMock
            .Setup(
                mock =>
                mock.CreateMethod(
                    _mutableType,
                    "add_Event",
                    accessorAttributes | MethodAttributes.SpecialName,
                    GenericParameterDeclaration.None,
                    It.IsAny <Func <GenericParameterContext, Type> >(),
                    It.IsAny <Func <GenericParameterContext, IEnumerable <ParameterDeclaration> > >(),
                    addBodyProvider))
            .Callback(
                (
                    MutableType declaringType,
                    string nameArgument,
                    MethodAttributes attributes,
                    IEnumerable <GenericParameterDeclaration> genericParameters,
                    Func <GenericParameterContext, Type> returnTypeProvider,
                    Func <GenericParameterContext, IEnumerable <ParameterDeclaration> > parameterProvider,
                    Func <MethodBodyCreationContext, Expression> bodyProvider) =>
            {
                var returnType = returnTypeProvider(null);
                Assert.That(returnType, Is.SameAs(typeof(void)));

                var parameter = parameterProvider(null).Single();
                Assert.That(parameter.Type, Is.SameAs(handlerType));
                Assert.That(parameter.Name, Is.EqualTo("handler"));
            })
            .Returns(fakeAddMethod)
            .Verifiable();
            _methodFactoryMock
            .Setup(
                mock =>
                mock.CreateMethod(
                    _mutableType,
                    "remove_Event",
                    accessorAttributes | MethodAttributes.SpecialName,
                    GenericParameterDeclaration.None,
                    It.IsAny <Func <GenericParameterContext, Type> >(),
                    It.IsAny <Func <GenericParameterContext, IEnumerable <ParameterDeclaration> > >(),
                    removeBodyProvider))
            .Callback(
                (
                    MutableType declaringType,
                    string nameArgument,
                    MethodAttributes attributes,
                    IEnumerable <GenericParameterDeclaration> genericParameters,
                    Func <GenericParameterContext, Type> returnTypeProvider,
                    Func <GenericParameterContext, IEnumerable <ParameterDeclaration> > parameterProvider,
                    Func <MethodBodyCreationContext, Expression> bodyProvider) =>
            {
                var returnType = returnTypeProvider(null);
                Assert.That(returnType, Is.SameAs(typeof(void)));

                var parameter = parameterProvider(null).Single();
                Assert.That(parameter.Type, Is.SameAs(handlerType));
                Assert.That(parameter.Name, Is.EqualTo("handler"));
            })
            .Returns(fakeRemoveMethod)
            .Verifiable();
            _methodFactoryMock
            .Setup(
                mock =>
                mock.CreateMethod(
                    _mutableType,
                    "raise_Event",
                    accessorAttributes | MethodAttributes.SpecialName,
                    GenericParameterDeclaration.None,
                    It.IsAny <Func <GenericParameterContext, Type> >(),
                    It.IsAny <Func <GenericParameterContext, IEnumerable <ParameterDeclaration> > >(),
                    raiseBodyProvider))
            .Callback(
                (
                    MutableType declaringType,
                    string nameArgument,
                    MethodAttributes attributes,
                    IEnumerable <GenericParameterDeclaration> genericParameters,
                    Func <GenericParameterContext, Type> returnTypeProvider,
                    Func <GenericParameterContext, IEnumerable <ParameterDeclaration> > parameterProvider,
                    Func <MethodBodyCreationContext, Expression> bodyProvider) =>
            {
                var returnType = returnTypeProvider(null);
                Assert.That(returnType, Is.SameAs(handlerReturnType));

                var parameters = parameterProvider(null).ToList();
                Assert.That(parameters[0].Type, Is.SameAs(typeof(object)));
                Assert.That(parameters[0].Name, Is.EqualTo("sender"));
                Assert.That(parameters[0].Attributes, Is.EqualTo(ParameterAttributes.None));
                Assert.That(parameters[1].Type, Is.SameAs(typeof(int).MakeByRefType()));
                Assert.That(parameters[1].Name, Is.EqualTo("outParam"));
                Assert.That(parameters[1].Attributes, Is.EqualTo(ParameterAttributes.Out));
            })
            .Returns(fakeRaiseMethod)
            .Verifiable();

            var result = _factory.CreateEvent(_mutableType, name, handlerType, accessorAttributes, addBodyProvider, removeBodyProvider, raiseBodyProvider);

            _methodFactoryMock.Verify();
            Assert.That(result.DeclaringType, Is.SameAs(_mutableType));
            Assert.That(result.Name, Is.EqualTo(name));
            Assert.That(result.Attributes, Is.EqualTo(EventAttributes.None));
            Assert.That(result.EventHandlerType, Is.SameAs(handlerType));
            Assert.That(result.MutableAddMethod, Is.SameAs(fakeAddMethod));
            Assert.That(result.MutableRemoveMethod, Is.SameAs(fakeRemoveMethod));
            Assert.That(result.MutableRaiseMethod, Is.SameAs(fakeRaiseMethod));
        }
コード例 #23
0
    /* This is a list of events and their arguments order
     * unless listed otherwise argument 0 is always the originating unit id (ex the moving unit, the firing unit)
     *
     *      AdminSpawnEvent: 1: latitude 2: longitude
     *
     *      AdminStatisticChangeEvent: 1: Controller name as a string 2: Parameter name as a string 3: new value
     *      AttackEvent: 1: target guid 2: weapon 3: damage //note damage of 0 indicates a miss
     *
     *      WeaponTargetEvent: 1: target unit id 2: weapon name 3: amount of shots
     *
     *      MoveEvent: 1: Vector3 of new position
     *
     *      DieEvent: no other arguments
     *
     *      EndOfTurnEvent: 0: the turn number
     *
     *      BackfireEvent: 1: the backfire damage
     *
     *      RemoveTargetEvent: 1: target guid 2: weapon name
     *
     *      UnitEmbarksEvent: 1: the smaller unit guid 2: the super unit guid
     *
     *      UnitUnEmbarksEvent: 1: the smaller unit guid 2: the super unit guid
     *
     *      WeatherChangeEvent: 0: the index of the new weather
     *
     *      ExplosionEvent: 0: The explosion instance
     *
     *      PlanMoveEvent: 0: Unit guid 1: user name 2: unit name 3: vector3 position 4: vector3 destination
     *
     */


    /**
     * Creates and returns an event with default priority of 0
     */
    public static GEvent CreateEvent(GEventType eType, object[] eArguments)
    {
        return(EventFactory.CreateEvent(eType, eArguments, 0));
    }