コード例 #1
0
 private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e)
 {
     if (e.ClickCount == 2)
     {
         EditEventCommand?.Execute(DataContext);
     }
 }
コード例 #2
0
ファイル: EditEventTest.cs プロジェクト: matdon90/SocialKnow
        public async Task ShouldThrowValidationExceptionDuringEventEditing(DateTime testDate, string testTitle, string testDescribtion, string testCategory, string testCity, string testVenue)
        {
            //arrange
            var loggedUser = await RunAsUserAsync("scott101@localhost", "Pa$$w0rd!");

            var eventId = await SendAsync(new Faker <CreateEventCommand>("en")
                                          .RuleFor(e => e.Id, f => f.Random.Guid())
                                          .RuleFor(e => e.Title, f => f.Lorem.Sentence())
                                          .RuleFor(e => e.Date, f => f.Date.Future())
                                          .RuleFor(e => e.Description, f => f.Lorem.Sentence(5))
                                          .RuleFor(e => e.Category, f => f.Lorem.Word())
                                          .RuleFor(e => e.City, f => f.Lorem.Word())
                                          .RuleFor(e => e.Venue, f => f.Lorem.Sentence(1)).Generate());

            var command = new EditEventCommand()
            {
                Id          = eventId,
                Date        = testDate,
                Title       = testTitle,
                Description = testDescribtion,
                Category    = testCategory,
                City        = testCity,
                Venue       = testVenue
            };

            //act

            //assert
            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().ThrowAsync <Common.Exceptions.ValidationException>();
        }
コード例 #3
0
ファイル: EventController.cs プロジェクト: alperkavusturan/SE
        public ActionResult <Event> Put([FromBody] UpdateEventDTO request)
        {
            var command = new EditEventCommand(_mapper.Map <Event>(request));
            var handler = _commandHandler.Build(command);

            return(Ok(handler.Execute()));
        }
コード例 #4
0
        public void ShouldNotCallHandleIfEventNotExist()
        {
            dbSetEvent.Setup(x => x.FindAsync(id)).Returns(null);
            context.Setup(x => x.Events).Returns(dbSetEvent.Object);

            EditEventCommandHandler editEventCommandHandler = new EditEventCommandHandler(context.Object, stringLocalizer.Object, mapper.Object);
            EditEventCommand        editEventCommand        = new EditEventCommand(eventDto);

            Func <Task> act = async() => await editEventCommandHandler.Handle(editEventCommand, new CancellationToken());

            act.Should().ThrowAsync <NotFoundException>();
        }
コード例 #5
0
        public void ShouldNotCallHandleIfNotSavedChanges()
        {
            dbSetEvent.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Event>(Task.FromResult(eventEntity)));
            context.Setup(x => x.Events).Returns(dbSetEvent.Object);
            context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(0));
            mapper.Setup(x => x.Map <Event>(eventDto)).Returns(eventEntity);

            EditEventCommandHandler editEventCommandHandler = new EditEventCommandHandler(context.Object, stringLocalizer.Object, mapper.Object);
            EditEventCommand        editEventCommand        = new EditEventCommand(eventDto);

            Func <Task> act = async() => await editEventCommandHandler.Handle(editEventCommand, new CancellationToken());

            act.Should().ThrowAsync <RestException>();
        }
コード例 #6
0
        public async Task ShouldCallHandle()
        {
            dbSetEvent.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Event>(Task.FromResult(eventEntity)));
            context.Setup(x => x.Events).Returns(dbSetEvent.Object);
            context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(1));
            mapper.Setup(x => x.Map <Event>(eventDto)).Returns(eventEntity);

            EditEventCommandHandler editEventCommandHandler = new EditEventCommandHandler(context.Object, stringLocalizer.Object, mapper.Object);
            EditEventCommand        editEventCommand        = new EditEventCommand(eventDto);

            var result = await editEventCommandHandler.Handle(editEventCommand, new CancellationToken());

            result.Should().Be(Unit.Value);
        }
コード例 #7
0
        public string DispatchCommand(string[] commandParameters)
        {
            string commandName = commandParameters[0];

            commandParameters = commandParameters.Skip(1).ToArray();
            string result = string.Empty;

            EventService eventService = new EventService();

            switch (commandName)
            {
            case "CreateEvent":
                CreateEventCommand createEvent = new CreateEventCommand(eventService);
                result = createEvent.Execute(commandParameters);
                break;

            case "DeleteEvent":
                DeleteEventCommand deleteEvent = new DeleteEventCommand(eventService);
                result = deleteEvent.Execute(commandParameters);
                break;

            case "EditEvent":
                EditEventCommand editEvent = new EditEventCommand(eventService);
                result = editEvent.Execute(commandParameters);
                break;

            case "ListEvents":
                ListEventsCommand listEvents = new ListEventsCommand(eventService);
                result = listEvents.Execute(commandParameters);
                break;

            case "Help":
                HelpCommand help = new HelpCommand();
                result = help.Execute(commandParameters);
                break;

            case "Exit":
                ExitCommand exit = new ExitCommand(eventService);
                result = exit.Execute(commandParameters);
                break;

            default:
                result = $@"Command {commandName} does not exist. Type ""Help"" to check the available commands.";
                break;
            }

            return(result);
        }
コード例 #8
0
        public async Task EventDoesNotExist()
        {
            var context = ServiceProvider.GetService <AllReadyContext>();

            var htb = new Organization
            {
                Id        = 123,
                Name      = "Humanitarian Toolbox",
                LogoUrl   = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl    = "http://www.htbox.org",
                Campaigns = new List <Campaign>()
            };

            var firePrev = new Campaign
            {
                Id   = 1,
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb,
                TimeZoneId           = "Central Standard Time"
            };

            htb.Campaigns.Add(firePrev);

            context.Organizations.Add(htb);
            context.SaveChanges();

            var vm = new EventEditViewModel
            {
                CampaignId = 1,
                TimeZoneId = "Central Standard Time"
            };

            var query = new EditEventCommand {
                Event = vm
            };
            var handler = new EditEventCommandHandler(context);
            var result  = await handler.Handle(query);

            Assert.True(result > 0);

            var data = context.Events.Count(_ => _.Id == result);

            Assert.True(data == 1);
        }
コード例 #9
0
ファイル: EditEvent.cs プロジェクト: mheggeseth/allReady
        public async Task EventDoesNotExist()
        {
            var context = ServiceProvider.GetService<AllReadyContext>();

            var htb = new Organization
            {
                Id = 123,
                Name = "Humanitarian Toolbox",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };

            var firePrev = new Campaign
            {
                Id = 1,
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb,
                TimeZoneId = "Central Standard Time"
            };
            htb.Campaigns.Add(firePrev);

            context.Organizations.Add(htb);
            context.SaveChanges();

            var vm = new EventEditViewModel
            {
                CampaignId = 1,
                TimeZoneId = "Central Standard Time"
            };

            var query = new EditEventCommand { Event = vm };
            var handler = new EditEventCommandHandler(context);
            var result = await handler.Handle(query);
            Assert.True(result > 0);

            var data = context.Events.Count(_ => _.Id == result);
            Assert.True(data == 1);
        }
コード例 #10
0
        public async Task ExistingEvent()
        {
            var context = ServiceProvider.GetService <AllReadyContext>();

            var htb = new Organization
            {
                Id        = 123,
                Name      = "Humanitarian Toolbox",
                LogoUrl   = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl    = "http://www.htbox.org",
                Campaigns = new List <Campaign>()
            };

            var firePrev = new Campaign
            {
                Id   = 1,
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb,
                TimeZoneId           = "Central Standard Time"
            };

            htb.Campaigns.Add(firePrev);

            var queenAnne = new Event
            {
                Id            = 100,
                Name          = "Queen Anne Fire Prevention Day",
                Campaign      = firePrev,
                CampaignId    = firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime   = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location      = new Location {
                    Id = 1
                },
                RequiredSkills = new List <EventSkill>()
            };

            context.Organizations.Add(htb);
            context.Events.Add(queenAnne);
            context.SaveChanges();

            const string newName = "Some new name value";

            var startDateTime = new DateTime(2015, 7, 12, 4, 15, 0);
            var endDateTime   = new DateTime(2015, 12, 7, 15, 10, 0);
            var vm            = new EventEditViewModel
            {
                CampaignId       = queenAnne.CampaignId,
                CampaignName     = queenAnne.Campaign.Name,
                Description      = queenAnne.Description,
                EndDateTime      = endDateTime,
                Id               = queenAnne.Id,
                ImageUrl         = queenAnne.ImageUrl,
                Location         = null,
                Name             = newName,
                RequiredSkills   = queenAnne.RequiredSkills,
                TimeZoneId       = "Central Standard Time",
                StartDateTime    = startDateTime,
                OrganizationId   = queenAnne.Campaign.ManagingOrganizationId,
                OrganizationName = queenAnne.Campaign.ManagingOrganization.Name,
            };
            var query = new EditEventCommand {
                Event = vm
            };
            var handler = new EditEventCommandHandler(context);
            var result  = await handler.Handle(query);

            Assert.Equal(100, result); // should get back the event id

            var data = context.Events.Single(_ => _.Id == result);

            Assert.Equal(newName, data.Name);

            Assert.Equal(2015, data.StartDateTime.Year);
            Assert.Equal(7, data.StartDateTime.Month);
            Assert.Equal(12, data.StartDateTime.Day);
            Assert.Equal(4, data.StartDateTime.Hour);
            Assert.Equal(15, data.StartDateTime.Minute);


            Assert.Equal(2015, data.EndDateTime.Year);
            Assert.Equal(12, data.EndDateTime.Month);
            Assert.Equal(7, data.EndDateTime.Day);
            Assert.Equal(15, data.EndDateTime.Hour);
            Assert.Equal(10, data.EndDateTime.Minute);
        }
コード例 #11
0
        public async Task ExistingEventUpdateLocation()
        {
            const string seattlePostalCode = "98117";

            var seattle = new Location
            {
                Id          = 1,
                Address1    = "123 Main Street",
                Address2    = "Unit 2",
                City        = "Seattle",
                PostalCode  = seattlePostalCode,
                Country     = "USA",
                State       = "WA",
                Name        = "Organizer name",
                PhoneNumber = "555-555-5555"
            };

            var htb = new Organization
            {
                Id        = 123,
                Name      = "Humanitarian Toolbox",
                LogoUrl   = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl    = "http://www.htbox.org",
                Campaigns = new List <Campaign>()
            };

            var firePrev = new Campaign
            {
                Id   = 1,
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb,
                TimeZoneId           = "Central Standard Time"
            };

            htb.Campaigns.Add(firePrev);

            var queenAnne = new Event
            {
                Id             = 100,
                Name           = "Queen Anne Fire Prevention Day",
                Campaign       = firePrev,
                CampaignId     = firePrev.Id,
                StartDateTime  = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime    = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location       = seattle,
                RequiredSkills = new List <EventSkill>()
            };

            var context = ServiceProvider.GetService <AllReadyContext>();

            context.Locations.Add(seattle);
            context.Organizations.Add(htb);
            context.Events.Add(queenAnne);
            context.SaveChanges();

            var newLocation = new Location
            {
                Address1    = "123 new address",
                Address2    = "new suite",
                PostalCode  = "98004",
                City        = "Bellevue",
                State       = "WA",
                Country     = "USA",
                Name        = "New name",
                PhoneNumber = "New number"
            }.ToEditModel();

            var locationEdit = new EventEditViewModel
            {
                CampaignId       = queenAnne.CampaignId,
                CampaignName     = queenAnne.Campaign.Name,
                Description      = queenAnne.Description,
                EndDateTime      = queenAnne.EndDateTime,
                Id               = queenAnne.Id,
                ImageUrl         = queenAnne.ImageUrl,
                Location         = newLocation,
                Name             = queenAnne.Name,
                RequiredSkills   = queenAnne.RequiredSkills,
                TimeZoneId       = "Central Standard Time",
                StartDateTime    = queenAnne.StartDateTime,
                OrganizationId   = queenAnne.Campaign.ManagingOrganizationId,
                OrganizationName = queenAnne.Campaign.ManagingOrganization.Name,
            };

            var query = new EditEventCommand {
                Event = locationEdit
            };
            var handler = new EditEventCommandHandler(context);
            var result  = await handler.Handle(query);

            Assert.Equal(100, result); // should get back the event id

            var data = context.Events.Single(a => a.Id == result);

            Assert.Equal(data.Location.Address1, newLocation.Address1);
            Assert.Equal(data.Location.Address2, newLocation.Address2);
            Assert.Equal(data.Location.City, newLocation.City);
            Assert.Equal(data.Location.PostalCode, newLocation.PostalCode);
            Assert.Equal(data.Location.State, newLocation.State);
            Assert.Equal(data.Location.Country, newLocation.Country);
            Assert.Equal(data.Location.PhoneNumber, newLocation.PhoneNumber);
            Assert.Equal(data.Location.Name, newLocation.Name);
        }
コード例 #12
0
ファイル: EditEvent.cs プロジェクト: mheggeseth/allReady
        public async Task ExistingEvent()
        {
            var context = ServiceProvider.GetService<AllReadyContext>();

            var htb = new Organization
            {
                Id = 123,
                Name = "Humanitarian Toolbox",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };

            var firePrev = new Campaign
            {
                Id = 1,
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb,
                TimeZoneId = "Central Standard Time"
            };
            htb.Campaigns.Add(firePrev);

            var queenAnne = new Event
            {
                Id = 100,
                Name = "Queen Anne Fire Prevention Day",
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = new Location { Id = 1 },
                RequiredSkills = new List<EventSkill>()
            };
            context.Organizations.Add(htb);
            context.Events.Add(queenAnne);
            context.SaveChanges();

            const string NEW_NAME = "Some new name value";

            var startDateTime = new DateTime(2015, 7, 12, 4, 15, 0);
            var endDateTime = new DateTime(2015, 12, 7, 15, 10, 0);
            var vm = new EventEditViewModel
            {
                CampaignId = queenAnne.CampaignId,
                CampaignName = queenAnne.Campaign.Name,
                Description = queenAnne.Description,
                EndDateTime = endDateTime,
                Id = queenAnne.Id,
                ImageUrl = queenAnne.ImageUrl,
                Location = null,
                Name = NEW_NAME,
                RequiredSkills = queenAnne.RequiredSkills,
                TimeZoneId = "Central Standard Time",
                StartDateTime = startDateTime,
                OrganizationId = queenAnne.Campaign.ManagingOrganizationId,
                OrganizationName = queenAnne.Campaign.ManagingOrganization.Name,
            };
            var query = new EditEventCommand { Event = vm };
            var handler = new EditEventCommandHandler(context);
            var result = await handler.Handle(query);
            Assert.Equal(100, result); // should get back the event id

            var data = context.Events.Single(_ => _.Id == result);
            Assert.Equal(NEW_NAME, data.Name);

            Assert.Equal(2015, data.StartDateTime.Year);
            Assert.Equal(7, data.StartDateTime.Month);
            Assert.Equal(12, data.StartDateTime.Day);
            Assert.Equal(4, data.StartDateTime.Hour);
            Assert.Equal(15, data.StartDateTime.Minute);
            Assert.Equal(-5, data.StartDateTime.Offset.TotalHours);

            Assert.Equal(2015, data.EndDateTime.Year);
            Assert.Equal(12, data.EndDateTime.Month);
            Assert.Equal(7, data.EndDateTime.Day);
            Assert.Equal(15, data.EndDateTime.Hour);
            Assert.Equal(10, data.EndDateTime.Minute);
            Assert.Equal(-6, data.EndDateTime.Offset.TotalHours);
        }
コード例 #13
0
ファイル: EditEvent.cs プロジェクト: mheggeseth/allReady
        public async Task ExistingEventUpdateLocation()
        {
            var seattlePostalCode = "98117";

            var seattle = new Location
            {
                Id = 1,
                Address1 = "123 Main Street",
                Address2 = "Unit 2",
                City = "Seattle",
                PostalCode = seattlePostalCode,
                Country = "USA",
                State = "WA",
                Name = "Organizer name",
                PhoneNumber = "555-555-5555"
            };

            var context = ServiceProvider.GetService<AllReadyContext>();

            var htb = new Organization
            {
                Id = 123,
                Name = "Humanitarian Toolbox",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };

            var firePrev = new Campaign
            {
                Id = 1,
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb,
                TimeZoneId = "Central Standard Time"
            };
            htb.Campaigns.Add(firePrev);

            var queenAnne = new Event
            {
                Id = 100,
                Name = "Queen Anne Fire Prevention Day",
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = seattle,
                RequiredSkills = new List<EventSkill>()
            };
            context.Locations.Add(seattle);
            context.Organizations.Add(htb);
            context.Events.Add(queenAnne);
            context.SaveChanges();

            var NEW_LOCATION = LocationExtensions.ToEditModel(new Location
            {
                Address1 = "123 new address",
                Address2 = "new suite",
                PostalCode = "98004",
                City = "Bellevue",
                State = "WA",
                Country = "USA",
                Name = "New name",
                PhoneNumber = "New number"
            });

            var locationEdit = new EventEditViewModel
            {
                CampaignId = queenAnne.CampaignId,
                CampaignName = queenAnne.Campaign.Name,
                Description = queenAnne.Description,
                EndDateTime = queenAnne.EndDateTime,
                Id = queenAnne.Id,
                ImageUrl = queenAnne.ImageUrl,
                Location = NEW_LOCATION,
                Name = queenAnne.Name,
                RequiredSkills = queenAnne.RequiredSkills,
                TimeZoneId = "Central Standard Time",
                StartDateTime = queenAnne.StartDateTime,
                OrganizationId = queenAnne.Campaign.ManagingOrganizationId,
                OrganizationName = queenAnne.Campaign.ManagingOrganization.Name,
            };

            var query = new EditEventCommand { Event = locationEdit };
            var handler = new EditEventCommandHandler(context);
            var result = await handler.Handle(query);
            Assert.Equal(100, result); // should get back the event id

            var data = context.Events.Single(a => a.Id == result);
            Assert.Equal(data.Location.Address1, NEW_LOCATION.Address1);
            Assert.Equal(data.Location.Address2, NEW_LOCATION.Address2);
            Assert.Equal(data.Location.City, NEW_LOCATION.City);
            Assert.Equal(data.Location.PostalCode, NEW_LOCATION.PostalCode);
            Assert.Equal(data.Location.State, NEW_LOCATION.State);
            Assert.Equal(data.Location.Country, NEW_LOCATION.Country);
            Assert.Equal(data.Location.PhoneNumber, NEW_LOCATION.PhoneNumber);
            Assert.Equal(data.Location.Name, NEW_LOCATION.Name);
        }
コード例 #14
0
 public ICommandHandler <EditEventCommand, Event> Build(EditEventCommand command)
 {
     return(new EditEventCommandHandler(_service, command));
 }