Ejemplo n.º 1
0
        public void IncludeConferenceWithOneTrackSuccessfully()
        {
            var stringTalkList = new List <string>();

            stringTalkList.Add("Rails Magic 60min");
            stringTalkList.Add("Ruby on Rails: Why We Should Move On 60min");
            stringTalkList.Add("Clojure Ate Scala(on my project) 45min");
            stringTalkList.Add("Programming in the Boondocks of Seattle 30min");
            stringTalkList.Add("Ruby vs.Clojure for Back - End Development 30min");
            stringTalkList.Add("Ruby on Rails Legacy App Maintenance 60min");
            stringTalkList.Add("A World Without HackerNews 30min");
            stringTalkList.Add("User Interface CSS in Rails Apps 30min");
            var talkService = new TalkService();
            var talks       = new List <Talk>();

            foreach (var item in stringTalkList)
            {
                talks.Add(talkService.IncludeTalk(item));
            }
            var service    = new ConferenceService();
            var conference = service.ScheduleTalks(talks);

            Assert.IsTrue(conference != null &&
                          conference.Tracks.Count == 1 &&
                          string.IsNullOrWhiteSpace(service.Error));
        }
Ejemplo n.º 2
0
        public void IncludeConferenceWithOnlyMorningSessionTrackSuccessfully()
        {
            var stringTalkList = new List <string>();

            stringTalkList.Add("Clojure Ate Scala(on my project) 45min");
            stringTalkList.Add("Programming in the Boondocks of Seattle 30min");
            stringTalkList.Add("Ruby vs.Clojure for Back - End Development 30min");
            stringTalkList.Add("User Interface CSS in Rails Apps 30min");
            var talkService = new TalkService();
            var talks       = new List <Talk>();

            foreach (var item in stringTalkList)
            {
                talks.Add(talkService.IncludeTalk(item));
            }
            var service    = new ConferenceService();
            var conference = service.ScheduleTalks(talks);

            Assert.IsTrue(conference != null &&
                          conference.Tracks.Count == 1 &&
                          conference.Tracks[0].HasNetworking == false &&
                          conference.Tracks[0].MorningTalks.Count > 0 &&
                          conference.Tracks[0].AfternoonTalks.Count == 0 &&
                          string.IsNullOrWhiteSpace(service.Error));
        }
Ejemplo n.º 3
0
        public void DontVisualizeScheduleWithNullConference()
        {
            var service  = new ConferenceService();
            var schedule = service.VisualizeSchedule(null);

            Assert.IsTrue(schedule == null && !string.IsNullOrWhiteSpace(service.Error));
        }
Ejemplo n.º 4
0
 public SessionViewModel(
     ConferenceService conferenceService,
     SessionSelectionModel sessionSelection)
 {
     _conferenceService = conferenceService;
     _sessionSelection  = sessionSelection;
 }
Ejemplo n.º 5
0
        public static ConferenceInfo PopulateConfereceData(Table table)
        {
            var svc        = new ConferenceService(BuildEventBus());
            var conference = BuildInternalConferenceInfo(table);

            svc.CreateConference(conference);
            svc.Publish(conference.Id);
            // publish seats
            ICollection <SeatType> createdSeats = CreateSeats(table);

            foreach (var seat in createdSeats)
            {
                svc.CreateSeat(conference.Id, seat);
            }

            var created = MessageLogHelper.CollectEvents <AvailableSeatsChanged>(conference.Id, createdSeats.Count);

            if (!created)
            {
                throw new TimeoutException("Conference creation error");
            }

            // Update the confInfo with the created seats

            conference.Seats.AddRange(createdSeats);

            return(conference);
        }
Ejemplo n.º 6
0
 protected override void OnInitialized()
 {
     editContext = new EditContext(Report);
     editContext.OnFieldChanged += HandleFieldChanged;
     speakers    = SpeakerService.GetSpeakers().ToImmutableArray();
     conferences = ConferenceService.GetConferences().ToImmutableArray();
     if (Report.Speakers is { })
Ejemplo n.º 7
0
        public IHttpActionResult Get(int id)
        {
            ConferenceService conferenceService = CreateConferenceService();
            var conference = conferenceService.GetConferenceById(id);

            return(Ok(conference));
        }
        public DeleteConferenceViewModel(bool modelState, Conference conference, ConferenceService service)
        {
            if (modelState)
            {
                try
                {
                    Status = CheckEntity(service, conference);
                }
                catch (InternetException ex)
                {
                    Message = ex.Message;
                    Status  = false;
                    return;
                }
                catch (DatabaseException ex)
                {
                    Message = ex.Message;
                    Status  = false;
                    return;
                }

                Message = " Delete successful!\n";
                Status  = true;
            }
            else
            {
                Message = " Invalid request!\n";
                Status  = false;
            }
        }
Ejemplo n.º 9
0
        public void VisualizeScheduleSuccessfully()
        {
            var service    = new ConferenceService();
            var conference = service.ScheduleTalks(DefaultTalks);
            var schedule   = service.VisualizeSchedule(conference);

            Assert.IsTrue(!string.IsNullOrWhiteSpace(schedule.ToString()) && string.IsNullOrWhiteSpace(service.Error));
        }
Ejemplo n.º 10
0
        public void DontIncludeConferenceWithoutTalks()
        {
            var service        = new ConferenceService();
            var talksCountZero = new List <Talk>();
            var conference     = service.ScheduleTalks(talksCountZero);

            Assert.IsTrue(conference == null && !string.IsNullOrWhiteSpace(service.Error));
        }
Ejemplo n.º 11
0
        private void InitaliseServices()
        {
            var repository = new ConferenceService();

            this.RegisterServiceInstance <IConferenceService>(repository);

            this.RegisterServiceInstance <ITwitterSearchProvider>(new TwitterSearchProvider());
        }
Ejemplo n.º 12
0
        private void InitialiseServices()
        {
            var repository = new ConferenceService();

            Cirrious.MvvmCross.Plugins.File.PluginLoader.Instance.EnsureLoaded();
            Mvx.RegisterSingleton <IConferenceService>(repository);
            Mvx.RegisterSingleton <ITwitterSearchProvider>(new TwitterSearchProvider());
        }
Ejemplo n.º 13
0
        public async Task ItGetsFeaturedConferences()
        {
            // Arrange
            // Act
            await Controller.GetFeatured();

            // Assert
            ConferenceService.Verify(x => x.GetFeatured(), Times.Once());
        }
Ejemplo n.º 14
0
        public async Task ItGetsConferences()
        {
            // Arrange
            // Act
            await Controller.GetAll(0, 1, nameof(Direction.Asc));

            // Assert
            ConferenceService.Verify(x => x.GetAll(0, 1, nameof(Direction.Asc)), Times.Once());
        }
Ejemplo n.º 15
0
        public void Setup()
        {
            // 初始化会议数据库
            using (var context = new ConferenceContext(this._dbName)) {
                if (context.Database.Exists())
                {
                    context.Database.Delete();
                }
                context.Database.Create();
            }

            // 模拟事件总线
            this._busEvents = new List <IEvent>();
            var busMock = new Mock <IEventBus>();

            busMock.Setup(b => b.Publish(It.IsAny <Envelope <IEvent> >()))
            .Callback <Envelope <IEvent> >(e => this._busEvents.Add(e.Body));
            busMock.Setup(b => b.Publish(It.IsAny <IEnumerable <Envelope <IEvent> > >()))
            .Callback <IEnumerable <Envelope <IEvent> > >(es => this._busEvents.AddRange(es.Select(e => e.Body)));

            this._service = new ConferenceService(busMock.Object, this._dbName);

            this._conference = new ConferenceInfo()
            {
                OwnerEmail  = "*****@*****.**",
                OwnerName   = "test owner",
                AccessCode  = "qwerty",
                Name        = "test conference",
                Description = "test conference description",
                Location    = "redmond",
                Slug        = "test",
                StartDate   = DateTime.UtcNow,
                EndDate     = DateTime.UtcNow.Add(TimeSpan.FromDays(2)),
                Seats       =
                {
                    new SeatType()
                    {
                        Name        = "general",
                        Description = "general description",
                        Price       = 100,
                        Quantity    = 10
                    }
                }
            };

            this._service.CreateConference(this._conference);

            this._placed = new OrderPlaced()
            {
                ConferenceId = Guid.NewGuid(),
                SourceId     = Guid.NewGuid(),
                AccessCode   = "asdf"
            };

            this._eventHandler = new OrderEventHandler(() => new ConferenceContext(_dbName));
            this._eventHandler.Handle(_placed);
        }
Ejemplo n.º 16
0
        public void IncludeConferenceWithTwoTracksSuccessfully()
        {
            var service    = new ConferenceService();
            var conference = service.ScheduleTalks(DefaultTalks);

            Assert.IsTrue(conference != null &&
                          conference.Tracks.Count == 2 &&
                          string.IsNullOrWhiteSpace(service.Error));
        }
Ejemplo n.º 17
0
        public async Task ItGetsConference()
        {
            // Arrange
            // Act
            await Controller.GetBySlug(_slug);

            // Assert
            ConferenceService.Verify(x => x.Get(_slug), Times.Once());
        }
Ejemplo n.º 18
0
 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     base.OnActionExecuting(filterContext);
     if (_conferenceService == null)
     {
         string appDataPath = Path.Combine(HttpContext.Request.PhysicalApplicationPath, "App_Data");
         _conferenceService = new ConferenceService(appDataPath);
     }
 }
        public ConferenceServiceTestBase()
        {
            Cache      = new Mock <ICacheManager>();
            Repository = new Mock <ISpeakerMeetRepository>();

            Repository.Setup(x => x.List(It.IsAny <ConferenceSpecification>()))
            .ReturnsAsync(new List <Conference>());

            Service = new ConferenceService(Cache.Object, Repository.Object);
        }
Ejemplo n.º 20
0
        public ScientistAddsConferenceViewModel(ScientistModel selectedScientist)
        {
            SelectedScientist = selectedScientist;
            List <Conference> conferences = ConferenceService.GetConferences();

            foreach (Conference c in conferences)
            {
                Conferences.Add(new ConferenceModel(c));
            }
        }
Ejemplo n.º 21
0
        public SessionViewModel(int sessionId)
        {
            _conferenceService = new ConferenceService();
            _id = sessionId;

            var session = _conferenceService.LoadSession(_id);

            _speaker = session.Speaker;
            _title   = session.Title;
        }
Ejemplo n.º 22
0
        public async Task <ActionResult> SpeakerDetails(string speakerName)
        {
            if (speakerName.Contains("tein"))
            {
                return(View("Error"));
            }

            var speaker = await ConferenceService.GetSpeakerByName(speakerName);

            return(View(speaker));
        }
Ejemplo n.º 23
0
        private async void LoadSpeakers(object sender, RoutedEventArgs e)
        {
            _loadingDone = false;
            var speakers = await ConferenceService.GetSpeakers();

            var speakerViewModels = from speaker in speakers
                                    select new SpeakerViewModel(speaker);

            lstSpeakers.ItemsSource = speakerViewModels.ToArray();
            _loadingDone            = true;
        }
Ejemplo n.º 24
0
        public async Task GivenException_ThenBadRequestResult()
        {
            // Arrange
            ConferenceService.Setup(x => x.Get(_slug)).Throws(new Exception());

            // Act
            var result = await Controller.GetBySlug(_slug);

            // Assert
            Assert.IsAssignableFrom <BadRequestObjectResult>(result.Result);
        }
Ejemplo n.º 25
0
        public async Task GivenEntityNotFoundException_ThenNotFoundResult()
        {
            // Arrange
            ConferenceService.Setup(x => x.Get(_id)).Throws(new EntityNotFoundException());

            // Act
            var result = await Controller.Get(_id);

            // Assert
            Assert.IsAssignableFrom <NotFoundObjectResult>(result.Result);
        }
 public static ConferenceInfo FindConference(string conferenceSlug)
 {
     var svc = new ConferenceService(BuildEventBus());
     var conference = svc.FindConference(conferenceSlug);
     if (null != conference)
     {
         if (conference.Seats.Count == 0)
             svc.FindSeatTypes(conference.Id).ToList().ForEach(s => conference.Seats.Add(s));
     }
     return conference;
 }
        public ConferenceAddsReportViewModel(Window window, ConferenceModel selectedConference)
        {
            Window = window;
            List <Report> reports = ConferenceService.GetReports(selectedConference.Conference);

            foreach (Report r in reports)
            {
                Reports.Add(new ReportModel(r));
            }
            SelectedConference = selectedConference;
        }
Ejemplo n.º 28
0
        public async Task GivenException_ThenBadRequestResult()
        {
            // Arrange
            ConferenceService.Setup(x => x.GetAll(0, 1, nameof(Direction.Desc))).Throws(new Exception());

            // Act
            var result = await Controller.GetAll(0, 1, nameof(Direction.Desc));

            // Assert
            Assert.IsAssignableFrom <BadRequestObjectResult>(result.Result);
        }
Ejemplo n.º 29
0
        public ConferenceViewModel()
        {
            _conferenceService = new ConferenceService();

            foreach (var session in _conferenceService.GetSessions())
            {
                _sessions.Add(new SessionHeaderViewModel
                {
                    Id    = session.Id,
                    Title = session.Title
                });
            }
        }
        public given_no_conference()
        {
            using (var context = new ConferenceContext(dbName))
            {
                if (context.Database.Exists())
                    context.Database.Delete();

                context.Database.CreateIfNotExists();
            }

            this.bus = new MemoryEventBus();
            this.service = new ConferenceService(this.bus, this.dbName);
        }
Ejemplo n.º 31
0
        public async Task GivenEntityNotFoundException_ThenItLogsWarning()
        {
            // Arrange
            var ex = new EntityNotFoundException();

            ConferenceService.Setup(x => x.Get(_id)).Throws(ex);

            // Act
            await Controller.Get(_id);

            // Assert
            Logger.Verify(x => x.LogWarning(ex, ex.Message), Times.Once());
        }
Ejemplo n.º 32
0
        public async Task GivenException_ThenItLogsError()
        {
            // Arrange
            var ex = new Exception();

            ConferenceService.Setup(x => x.Get(_slug)).Throws(ex);

            // Act
            await Controller.GetBySlug(_slug);

            // Assert
            Logger.Verify(x => x.LogError(ex, ex.Message), Times.Once());
        }
Ejemplo n.º 33
0
        public static void CreateSeats(string conferenceSlug, Table table)
        {
            var svc = new ConferenceService(BuildEventBus());
            var conference = FindConference(conferenceSlug);

            foreach (var row in table.Rows)
            {
                svc.CreateSeat(conference.Id, new SeatType
                                            {
                                                Name = row["Name"],
                                                Description = row["Description"],
                                                Quantity = int.Parse(row["Quantity"]),
                                                Price = decimal.Parse(row["Price"])
                                            });
            }
        }
        public given_no_conference()
        {
            using (var context = new ConferenceContext(dbName))
            {
                if (context.Database.Exists())
                    context.Database.Delete();

                context.Database.Create();
            }

            this.busEvents = new List<IEvent>();
            var busMock = new Mock<IEventBus>();
            busMock.Setup(b => b.Publish(It.IsAny<Envelope<IEvent>>())).Callback<Envelope<IEvent>>(e => busEvents.Add(e.Body));
            busMock.Setup(b => b.Publish(It.IsAny<IEnumerable<Envelope<IEvent>>>())).Callback<IEnumerable<Envelope<IEvent>>>(es => busEvents.AddRange(es.Select(e => e.Body)));

            this.service = new ConferenceService(busMock.Object, this.dbName);
        }
        public static ConferenceInfo PopulateConfereceData(Table table)
        {
            string conferenceSlug = Slug.CreateNew().Value;
            var svc = new ConferenceService(BuildEventBus());
            var conference = BuildConferenceInfo(table, conferenceSlug);
            svc.CreateConference(conference);
            svc.Publish(conference.Id);

            Registration.ReadModel.Conference published = null;
            while(published == null || 
                !published.IsPublished || 
                published.Seats.Count != table.Rows.Count)
            {
                published = RegistrationHelper.FindConference(conference.Id);
                Thread.Sleep(100);
            }

            return conference;
        }
Ejemplo n.º 36
0
        public static ConferenceInfo PopulateConfereceData(Table table)
        {
            var svc = new ConferenceService(BuildEventBus());
            var conference = BuildInternalConferenceInfo(table);
            svc.CreateConference(conference);
            svc.Publish(conference.Id);
            // publish seats
            ICollection<SeatType> createdSeats = CreateSeats(table);
            foreach (var seat in createdSeats)
            {
                svc.CreateSeat(conference.Id, seat);
            }

            var created = MessageLogHelper.CollectEvents<AvailableSeatsChanged>(conference.Id, createdSeats.Count);

            if(!created)
                throw new TimeoutException("Conference creation error");

            // Update the confInfo with the created seats
            
            conference.Seats.AddRange(createdSeats);

            return conference;
        }
Ejemplo n.º 37
0
        public static void Register(HttpConfiguration config)
        {
            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
            // Web API configuration and services
            // Configure Web API to use only bearer token authentication.

            // Web API routes
            config.MapHttpAttributeRoutes();

            var cors = new EnableCorsAttribute("*", "*", "*");
            config.EnableCors(cors);

            config.Filters.Add(new ExceptionHandlingAttribute());
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            var container = new UnityContainer();

            try
            {
                // repositories used by the application

                container.RegisterType<ConferenceRegistrationDbContext>(new TransientLifetimeManager(), new InjectionConstructor("ConferenceRegistration"));
                container.RegisterType<PaymentsReadDbContext>(new TransientLifetimeManager(), new InjectionConstructor("Payments"));

                var cache = new MemoryCache("ReadModel");
                container.RegisterType<IOrderDao, OrderDao>();
                container.RegisterType<IConferenceDao, CachingConferenceDao>(
                    new ContainerControlledLifetimeManager(),
                    new InjectionConstructor(new ResolvedParameter<ConferenceDao>(), cache));
                container.RegisterType<IPaymentDao, PaymentDao>();

                // configuration specific settings

                var serializer = new JsonTextSerializer();
                container.RegisterInstance<ITextSerializer>(serializer);

                container.RegisterType<IBlobStorage, SqlBlobStorage>(new ContainerControlledLifetimeManager(), new InjectionConstructor("BlobStorage"));
                container.RegisterType<Infrastructure.Sql.Messaging.IMessageSender, MessageSender>(
                    "Commands", new TransientLifetimeManager(), new InjectionConstructor(Database.DefaultConnectionFactory, "SqlBus", "SqlBus.Commands"));
                container.RegisterType<ICommandBus, Infrastructure.Sql.Messaging.CommandBus>(
                    new ContainerControlledLifetimeManager(), new InjectionConstructor(new ResolvedParameter<Infrastructure.Sql.Messaging.IMessageSender>("Commands"), serializer));


                config.DependencyResolver = new UnityResolver(container);

                IEventBus eventBus = null;
//#if LOCAL
            eventBus = new Infrastructure.Sql.Messaging.EventBus(new MessageSender(Database.DefaultConnectionFactory, "SqlBus", "SqlBus.Events"), serializer);
//#else
//                var settings = InfrastructureSettings.Read(HttpContext.Current.Server.MapPath(@"~\bin\Settings.xml")).ServiceBus;

//                if (!MaintenanceMode.IsInMaintainanceMode)
//                {
//                    new ServiceBusConfig(settings).Initialize();
//                }

//                eventBus = new Infrastructure.Azure.Messaging.EventBus(new TopicSender(settings, "conference/events"), new StandardMetadataProvider(), serializer);
//#endif

                container.RegisterInstance<IEventBus>(eventBus);

                var conferenceService = new ConferenceService(eventBus);

                container.RegisterInstance<ConferenceService>(conferenceService);
            }
            catch
            {
                container.Dispose();
                throw;
            }
        }
Ejemplo n.º 38
0
 public ConferenceController(IConferenceDao dao, ConferenceService conferenceService)
 {
     this._dao = dao;
     _tracer = GlobalConfiguration.Configuration.Services.GetTraceWriter();
     service = conferenceService;
 }
        public given_an_existing_conference_with_a_seat()
        {
            using (var context = new ConferenceContext(dbName))
            {
                if (context.Database.Exists())
                    context.Database.Delete();

                context.Database.CreateIfNotExists();
            }

            this.busEvents = new List<IEvent>();
            var busMock = new Mock<IEventBus>();
            busMock.Setup(b => b.Publish(It.IsAny<Envelope<IEvent>>())).Callback<Envelope<IEvent>>(e => busEvents.Add(e.Body));
            busMock.Setup(b => b.Publish(It.IsAny<IEnumerable<Envelope<IEvent>>>())).Callback<IEnumerable<Envelope<IEvent>>>(es => busEvents.AddRange(es.Select(e => e.Body)));
            this.service = new ConferenceService(busMock.Object, this.dbName);
            this.conference = new ConferenceInfo
            {
                OwnerEmail = "*****@*****.**",
                OwnerName = "test owner",
                AccessCode = "qwerty",
                Name = "test conference",
                Description = "test conference description",
                Location = "redmond",
                Slug = "test",
                StartDate = DateTime.UtcNow,
                EndDate = DateTime.UtcNow.Add(TimeSpan.FromDays(2)),
                IsPublished = true,
                Seats = 
                {
                    new SeatType
                    {
                        Name = "general", 
                        Description = "general description", 
                        Price = 100, 
                        Quantity = 10,
                    }
                }
            };
            service.CreateConference(this.conference);
        }
 public ConferenceConfigurationIntegrationSteps()
 {
     conferenceService = new ConferenceService(ConferenceHelper.BuildEventBus());    
 }
        public given_an_existing_conference_with_a_seat()
        {
            using (var context = new ConferenceContext(dbName))
            {
                if (context.Database.Exists())
                    context.Database.Delete();

                context.Database.CreateIfNotExists();
            }

            this.bus = new MemoryEventBus();
            this.service = new ConferenceService(this.bus, this.dbName);
            this.conference = new ConferenceInfo
            {
                OwnerEmail = "*****@*****.**",
                OwnerName = "test owner",
                AccessCode = "qwerty",
                Name = "test conference",
                Description = "test conference description",
                Location = "redmond",
                Slug = "test",
                StartDate = DateTime.UtcNow,
                EndDate = DateTime.UtcNow.Add(TimeSpan.FromDays(2)),
                IsPublished = true,
                Seats = 
                {
                    new SeatType
                    {
                        Name = "general", 
                        Description = "general description", 
                        Price = 100, 
                        Quantity = 10,
                    }
                }
            };
            service.CreateConference(this.conference);
        }
Ejemplo n.º 42
0
 public static Order FindOrder(Guid conferenceId, Guid orderId)
 {
     var svc = new ConferenceService(BuildEventBus());
     return svc.FindOrders(conferenceId).FirstOrDefault(o => o.Id == orderId);
 }