コード例 #1
0
        public void Get_ById_Returns_FoundItem()
        {
            var data = new List <Currency>
            {
                new Currency {
                    CurrencyId = 2, IsoCode = "BB", Name = "YYY"
                },
                new Currency {
                    CurrencyId = 1, IsoCode = "AA", Name = "XXX"
                },
                new Currency {
                    CurrencyId = 3, IsoCode = "CC", Name = "UUU"
                },
            };

            var mockSet = new Mock <DbSet <Currency> >().SetupData(data,
                                                                   objects => data.SingleOrDefault(d => d.CurrencyId == (long)objects.First()));
            var mockContext = new Mock <CountryContext>();

            mockContext.Setup(c => c.Currencies).Returns(mockSet.Object);
            mockContext.Setup(c => c.Set <Currency>()).Returns(mockSet.Object);

            var service = new CurrencyRepository(mockContext.Object);

            // Act
            var item = service.Get(2);

            Assert.IsNotNull(item);
            Assert.AreEqual(item.IsoCode, "BB");
        }
コード例 #2
0
        public void Get_Returns_Sorted_Items()
        {
            var data = new List <Currency>
            {
                new Currency {
                    IsoCode = "BB", Name = "YYY"
                },
                new Currency {
                    IsoCode = "AA", Name = "XXX"
                },
                new Currency {
                    IsoCode = "CC", Name = "UUU"
                },
            };

            var mockSet     = new Mock <DbSet <Currency> >().SetupData(data);
            var mockContext = new Mock <CountryContext>();

            mockContext.Setup(c => c.Currencies).Returns(mockSet.Object);

            var service = new CurrencyRepository(mockContext.Object);

            // Act
            var items = service.Get().ToList();

            Assert.IsNotNull(items);
            Assert.AreEqual(items.Count, data.Count);
            Assert.AreEqual(items[0].IsoCode, "AA");
            Assert.AreEqual(items[1].IsoCode, "BB");
            Assert.AreEqual(items[2].IsoCode, "CC");
        }
コード例 #3
0
        public void Get_ByIsoCode_Returns_FoundItem()
        {
            var data = new List <Currency>
            {
                new Currency {
                    IsoCode = "BB", Name = "YYY"
                },
                new Currency {
                    IsoCode = "AA", Name = "XXX"
                },
                new Currency {
                    IsoCode = "CC", Name = "UUU"
                },
            };

            var mockSet     = new Mock <DbSet <Currency> >().SetupData(data);
            var mockContext = new Mock <CountryContext>();

            mockContext.Setup(c => c.Currencies).Returns(mockSet.Object);

            var service = new CurrencyRepository(mockContext.Object);

            // Act
            var item = service.Get("BB");

            Assert.IsNotNull(item);
            Assert.AreEqual(item.IsoCode, "BB");
        }
コード例 #4
0
        public void A_ChangedCountry_modifies_Existing_country_in_the_database()
        {
            var bootStrapper = new BootStrapper();
            bootStrapper.StartServices();
            var serviceEvents = bootStrapper.GetService<IServiceEvents>();
            //1.- Create message
            var aggr = GenerateRandomAggregate();

            //2.- Create the tuple in the database
            var repository = new CurrencyRepository(_configuration.TestServer);
            repository.Insert(aggr);

            //3.- Change the aggregate
            aggr.IsoCodeChar = StringExtension.RandomString(3);
            aggr.IsoCodeNum = StringExtension.RandomString(3);
            aggr.SapCode = StringExtension.RandomString(2);

            //4.- Emit message
            var message = GenerateMessage(aggr);
            message.MessageType = typeof(ChangedCurrency).Name;
            serviceEvents.AddIncommingEvent(new IncommingEvent { @event = message });

            //5.- Load the saved country
            var currency = repository.Get(aggr.Id);
            //6.- Check equality
            Assert.True(ObjectExtension.AreEqual(aggr, currency));
        }
コード例 #5
0
        public Currency GetCurrency(int id)
        {
            Currency           currency = new Currency();
            CurrencyRepository repo     = new CurrencyRepository();

            if (currency != null)
            {
                currency = ParserCurrency(repo.Get(id));
            }
            return(currency);
        }
コード例 #6
0
        public ActionResult AddCurrency(string currencyName, string currencySymbol)
        {
            Currency currency = new Currency()
            {
                CurrencyName   = currencyName,
                CurrencySymbol = currencySymbol
            };
            CurrencyRepository currencyRepository = new CurrencyRepository();

            currencyRepository.Add(currency);
            currencyRepository.PersistChanges();

            Currency dbCurrency = currencyRepository.Get(currency.Id);

            return(Content($"Inserted currency id: {dbCurrency.Id}"));
        }
コード例 #7
0
 public void A_RegisteredCurrency_creates_a_new_currency_in_the_database()
 {
     var bootStrapper = new BootStrapper();
     bootStrapper.StartServices();
     var serviceEvents = bootStrapper.GetService<IServiceEvents>();
     //1.- Create message
     var aggr = GenerateRandomAggregate();
     var message = GenerateMessage(aggr);
     //2.- Emit message
     serviceEvents.AddIncommingEvent(new IncommingEvent { @event = message });
     //3.- Load the saved country
     var repository = new CurrencyRepository(_configuration.TestServer);
     var currency = repository.Get(aggr.Id);
     //4.- Check equality
     Assert.True(ObjectExtension.AreEqual(aggr, currency));
 }
コード例 #8
0
        public void A_UnregisteredCountry_modifies_Existing_country_in_the_database()
        {
            var bootStrapper = new BootStrapper();
            bootStrapper.StartServices();
            var serviceEvents = bootStrapper.GetService<IServiceEvents>();
            //1.- Create message
            var aggr = GenerateRandomAggregate();

            //2.- Create the tuple in the database
            var repository = new CurrencyRepository(_configuration.TestServer);
            repository.Insert(aggr);

            //2.- Emit message
            var message = GenerateMessage(aggr);
            message.MessageType = typeof(UnregisteredCurrency).Name;
            serviceEvents.AddIncommingEvent(new IncommingEvent { @event = message });

            var country = repository.Get(aggr.Id);
            Assert.Null(country);
            
        }