Exemplo n.º 1
0
        static async Task Main(string[] args)
        {
            var userStore = new UserStore();

            while (true)
            {
                Console.WriteLine("Enter user id to find the user name:");
                string input = Console.ReadLine();

                if (input == "exit")
                {
                    break;
                }

                if (int.TryParse(input, out int id))
                {
                    var state        = userStore.GetById(id);
                    var actionResult = state.Observe <IActionResult>(UserFound, UserNotFound);

                    Console.WriteLine($@"Emulating http response to retreive user by entered id: Status code: {actionResult.StatusCode}, body: ""{actionResult.Body}""");

                    if (actionResult.StatusCode == 404)
                    {
                        Console.WriteLine("Please enter the name to add the user:"******"Emulating http response to insert a new user by entered id: Status code: {addUserResult.StatusCode}, body: ""{addUserResult.Body}""");
                    }
                }
            }
        }
Exemplo n.º 2
0
        public async Task StoreUser()
        {
            var context      = Helpers.GetMockContext();
            var stateManager = new MockReliableStateManager();
            var service      = new UserStore(context, stateManager);


            var currencyAmounts = new Dictionary <string, double>();

            currencyAmounts.Add(CurrencyPair.GBPUSD.GetBuyerWantCurrency(), 21);
            var sutUser = new User("42", "Anders", currencyAmounts, new List <string>()
            {
                "t1"
            });

            //create state
            await service.AddUserAsync(sutUser, CancellationToken.None);

            //get state
            var dictionary = await stateManager.TryGetAsync <IReliableDictionary <string, User> >(UserStore.StateManagerKey);

            var actual = (await dictionary.Value.TryGetValueAsync(new MockTransaction(stateManager, 1), sutUser.Id)).Value;

            Assert.Equal(sutUser, actual);
        }