public void ThenTheFollowingSalesRecordShouldBeRecorded(Table table)
        {
            var saleRecord = table.CreateInstance <CreateSaleRecordModel>();

            var database = _context.DatabaseService;

            var sale = database.Sales.Last();

            var lookup = new DatabaseLookup(database);

            var customerId = lookup.GetCustomerId(saleRecord.Customer);

            var employeeId = lookup.GetEmployeeId(saleRecord.Employee);

            var productId = lookup.GetProductIdByName(saleRecord.Product);

            Assert.That(
                sale.Date,
                Is.EqualTo(saleRecord.Date));

            Assert.That(
                sale.Customer.Id,
                Is.EqualTo(customerId));

            Assert.That(
                sale.Employee.Id,
                Is.EqualTo(employeeId));

            Assert.That(
                sale.Product.Id,
                Is.EqualTo(productId));

            Assert.That(
                sale.UnitPrice,
                Is.EqualTo(saleRecord.UnitPrice));

            Assert.That(
                sale.Quantity,
                Is.EqualTo(saleRecord.Quantity));

            Assert.That(
                sale.TotalPrice,
                Is.EqualTo(saleRecord.TotalPrice));
        }
        public async Task <Message> Post([FromBody] Message message)
        {
            if (message.Type == "Message")
            {
                BotFlow myBotFlow =
                    BotFlow.DisplayMessage("Hello I am breakfastbot and will do my best to serve you breakfast! Do you want milk?")
                    .WithThumbnail("http://www.mysite.com/milk.png")
                    .WithOption("Yes",
                                BotFlow.DisplayMessage("Here's your milk.")
                                .Do(() => Ordering.OrderMilk()))
                    .WithOption("No",
                                BotFlow.DisplayMessage("Well, then what do you want? ;)")
                                .WithOption("Cookies",
                                            BotFlow.DisplayMessage("Here are your cookies")
                                            .Do(() => Ordering.OrderCookies()))
                                .WithOption("Waffles",
                                            BotFlow.DisplayMessage("Here are your waffles")
                                            .Do(() => Ordering.OrderWaffles()))
                                .WithOption("Nothing",
                                            BotFlow.CalculateMessage(async() =>
                {
                    // Retrieve breakfast from database
                    string top10Breakfasts = await DatabaseLookup.GetTop10Breakfasts();
                    return("Maybe you want some ideas - here are the top 10 breakfasts according to our database: " + top10Breakfasts +
                           ". Do any of these sound good?");
                })
                                            .WithOption("Yes",
                                                        BotFlow.DisplayMessage("Great! Click here to browse to our breakfast webpage to find them.")
                                                        .WithOptionLink("Breakfast website", "http://www.microsoft.com")
                                                        )
                                            .WithOption("No",
                                                        BotFlow.DisplayMessage("You must be kidding - everybody likes breakfast!")
                                                        )
                                            )
                                )
                    .FinishWith("Have a great day!");

                return(await Conversation.SendAsync(message, () => myBotFlow.BuildDialogChain()));
            }

            return(HandleSystemMessage(message));
        }
Esempio n. 3
0
        public void GivenTheFollowingSaleInfo(Table table)
        {
            var saleInfo = table.CreateInstance <CreateSaleInfoModel>();

            _context.Mocker.GetMock <IDateService>()
            .Setup(p => p.GetDate())
            .Returns(saleInfo.Date);

            var mockDatabase = _context.Mocker.GetMock <IDatabaseContext>();

            var lookup = new DatabaseLookup(mockDatabase.Object);

            _model = new CreateSaleModel
            {
                CustomerId = lookup.GetCustomerId(saleInfo.Customer),
                EmployeeId = lookup.GetEmployeeId(saleInfo.Employee),
                ProductId  = lookup.GetProductIdByName(saleInfo.Product),
                Quantity   = saleInfo.Quantity
            };
        }
        /// <summary>
        /// Loads details about the aircraft from the database.
        /// </summary>
        /// <param name="databaseLookup"></param>
        private void LoadAircraftDetails(DatabaseLookup databaseLookup)
        {
            var aircraft = databaseLookup.Aircraft;
            bool lookupPicture = databaseLookup.AlwaysRefreshPicture;

            string icao24;
            int uniqueId;
            lock(aircraft) {
                icao24 = aircraft.Icao24;
                uniqueId = aircraft.UniqueId;
            }

            var baseStationAircraft = BaseStationDatabase.GetAircraftByCode(icao24);
            if(baseStationAircraft != null) {
                var flightsCount = BaseStationDatabase.GetCountOfFlightsForAircraft(baseStationAircraft, new SearchBaseStationCriteria() { ToDate = DateTime.MaxValue });
                var typeDetails = String.IsNullOrEmpty(baseStationAircraft.ICAOTypeCode) ? null : StandingDataManager.FindAircraftType(baseStationAircraft.ICAOTypeCode);

                Route route = null;
                if(!String.IsNullOrEmpty(aircraft.Callsign) && !String.IsNullOrEmpty(baseStationAircraft.OperatorFlagCode) && Char.IsDigit(aircraft.Callsign[0])) {
                    route = StandingDataManager.FindRoute(String.Format("{0}{1}", baseStationAircraft.OperatorFlagCode, aircraft.Callsign));
                }

                lock(_AircraftMapLock) {
                    lock(aircraft) {
                        GenerateDataVersion(aircraft);

                        if(String.IsNullOrEmpty(aircraft.Registration) && !String.IsNullOrEmpty(baseStationAircraft.Registration)) lookupPicture = true;

                        aircraft.Registration = baseStationAircraft.Registration;
                        aircraft.Type = baseStationAircraft.ICAOTypeCode;
                        aircraft.Manufacturer = baseStationAircraft.Manufacturer;
                        aircraft.Model = baseStationAircraft.Type;
                        aircraft.ConstructionNumber = baseStationAircraft.SerialNo;
                        aircraft.Operator = baseStationAircraft.RegisteredOwners;
                        aircraft.OperatorIcao = baseStationAircraft.OperatorFlagCode;
                        aircraft.IsInteresting = baseStationAircraft.Interested;
                        aircraft.UserTag = baseStationAircraft.UserTag;
                        aircraft.FlightsCount = flightsCount;

                        ApplyRoute(aircraft, route);
                        ApplyAircraftType(aircraft, typeDetails);
                    }
                }
            }

            if(lookupPicture) _PictureLookupQueue.Enqueue(aircraft);

            if(baseStationAircraft == null || String.IsNullOrEmpty(baseStationAircraft.Registration)) {
                if(databaseLookup.QueueForRefresh) {
                    lock(_RefreshDatabaseTimesLock) {
                        var scheduledRefreshTime = Provider.UtcNow.AddMinutes(1);
                        if(_RefreshDatabaseTimes.ContainsKey(uniqueId)) _RefreshDatabaseTimes[uniqueId] = scheduledRefreshTime;
                        else                                            _RefreshDatabaseTimes.Add(uniqueId, scheduledRefreshTime);
                    }
                }
            }
        }