Ejemplo n.º 1
0
        public void GetInstrumentById_Successful()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new LibraryContext(options);
            IInstrumentRepository instrumentRepository = new InstrumentRepository(context);

            var instru = new InstrumentTO {
                Name = "Saxophone"
            };
            var instru2 = new InstrumentTO {
                Name = "Trumpet"
            };
            var instru3 = new InstrumentTO {
                Name = "Flute"
            };
            var AddedInstru  = instrumentRepository.Add(instru);
            var AddedInstru2 = instrumentRepository.Add(instru2);
            var AddedInstru3 = instrumentRepository.Add(instru3);

            context.SaveChanges();

            //Act
            var result  = instrumentRepository.GetById(1);
            var result2 = instrumentRepository.GetById(2);
            var result3 = instrumentRepository.GetById(3);

            //Assert
            Assert.AreEqual("Saxophone", result.Name);
            Assert.AreEqual("Trumpet", result2.Name);
            Assert.AreEqual("Flute", result3.Name);
        }
Ejemplo n.º 2
0
        private void _client_BatchContractDetailsEnd(object sender, ContractDetailsEndEventArgs e)
        {
            if (_tmpContractDetails.Count == 1)
            {
                using (var context = new MyDBContext())
                {
                    var        im         = new InstrumentRepository(context);
                    Instrument instrument = ContractToInstrument(_tmpContractDetails[0]);

                    if (instrument != null && TryAddInstrument(im, instrument))
                    {
                        //successfully added the symbol
                        _symbolsAdded.Add(instrument.Symbol);
                    }
                }
            }

            _tmpContractDetails.Clear();

            if (_queuedSymbols.Count == 0)
            {
                //in this case, we have completed all the requests
                BatchRequestJobCompleted();
            }
            else
            {
                //we're not done, send the next request
                SendNextRequestInBatch();
            }
        }
        public void GetAllTest()
        {
            InstrumentRepository repo        = new InstrumentRepository();
            List <C_Instrument>  instruments = repo.GetAll();

            Assert.IsTrue(instruments.Count > 0);
        }
Ejemplo n.º 4
0
        public IEnumerable <Instrument> GetAll()
        {
            InstrumentRepository instrumentRepository = new InstrumentRepository();
            var retorno = instrumentRepository.GetAll();

            return(retorno);
        }
Ejemplo n.º 5
0
        private void AddBtn_Click(object sender, RoutedEventArgs e)
        {
            int count = 0;

            using (var context = new MyDBContext())
            {
                var instrumentSource = new InstrumentRepository(context);
                foreach (FredUtils.FredSeries series in InstrumentGrid.SelectedItems)
                {
                    var newInstrument = FredUtils.SeriesToInstrument(series);
                    newInstrument.Datasource = _thisDS;

                    try
                    {
                        if (instrumentSource.AddInstrument(newInstrument) != null)
                        {
                            count++;
                        }
                        AddedInstruments.Add(newInstrument);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error");
                    }
                }
            }
            StatusLabel.Content = string.Format("{0}/{1} instruments added.", count, InstrumentGrid.SelectedItems.Count);
        }
Ejemplo n.º 6
0
        private void ExecuteAddSelectedInstruments(IList selectedInstruments)
        {
            if (selectedInstruments == null)
            {
                throw new ArgumentNullException(nameof(selectedInstruments));
            }
            if (selectedInstruments.Count == 0)
            {
                return;
            }

            int count = 0;

            using (var context = new MyDBContext())
            {
                var instrumentSource = new InstrumentRepository(context);

                foreach (Instrument newInstrument in selectedInstruments)
                {
                    if (TryAddInstrument(instrumentSource, newInstrument))
                    {
                        count++;
                    }
                }
            }

            Status = string.Format("{0}/{1} instruments added.", count, selectedInstruments.Count);
        }
Ejemplo n.º 7
0
        public void AddInstrument_AddExistingInstrument_DoNotInsertTwiceInDb()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new LibraryContext(options);
            IInstrumentRepository instrumentRepository = new InstrumentRepository(context);

            //Act
            var instru = new InstrumentTO {
                Name = "Saxophone"
            };
            var instru2 = new InstrumentTO {
                Id = 2, Name = "Saxophone"
            };
            var result  = instrumentRepository.Add(instru);
            var result2 = instrumentRepository.Add(instru2);

            context.SaveChanges();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, instrumentRepository.GetAll().Count());
        }
Ejemplo n.º 8
0
        private void AddBtn_Click(object sender, RoutedEventArgs e)
        {
            int count = 0;

            using (var context = new MyDBContext())
            {
                var instrumentSource = new InstrumentRepository(context);
                foreach (Instrument newInstrument in InstrumentGrid.SelectedItems)
                {
                    if (newInstrument.Exchange != null)
                    {
                        newInstrument.ExchangeID = newInstrument.Exchange.ID;
                    }
                    if (newInstrument.PrimaryExchange != null)
                    {
                        newInstrument.PrimaryExchangeID = newInstrument.PrimaryExchange.ID;
                    }

                    try
                    {
                        if (instrumentSource.AddInstrument(newInstrument) != null)
                        {
                            count++;
                        }
                        AddedInstruments.Add(newInstrument);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error");
                    }
                }
            }
            StatusLabel.Content = string.Format("{0}/{1} instruments added.", count, InstrumentGrid.SelectedItems.Count);
        }
Ejemplo n.º 9
0
        public void UpdateInstrument_Successful()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new LibraryContext(options);
            IInstrumentRepository instrumentRepository = new InstrumentRepository(context);

            var instru = new InstrumentTO {
                Name = "Saxophone"
            };
            var instru2 = new InstrumentTO {
                Name = "Trumpet"
            };
            var instru3 = new InstrumentTO {
                Name = "Flute"
            };
            var AddedInstru  = instrumentRepository.Add(instru);
            var AddedInstru2 = instrumentRepository.Add(instru2);
            var AddedInstru3 = instrumentRepository.Add(instru3);

            context.SaveChanges();

            //Act
            AddedInstru.Name = "PouetPouet";
            var test = instrumentRepository.Update(AddedInstru);

            context.SaveChanges();

            //Assert
            Assert.AreEqual(3, instrumentRepository.GetAll().Count());
            Assert.AreEqual("PouetPouet", test.Name);
        }
Ejemplo n.º 10
0
        public void CreateDeliveriesFromPendingItems_ValidPendingDeliveryItems_DeliveriesCreated()
        {
            var dispatcher     = MockRepository.GenerateMock <IQueueDispatcher <IMessage> >();
            var userRepository = new UserAccountRepository();
            var user           = userRepository.GetByEmail("*****@*****.**", false);
            var userContext    = new TestUserContext(user);

            var quoteRepository        = new QuoteRepository();
            var quoteItemRepository    = new QuoteItemRepository();
            var customerRepository     = new CustomerRepository();
            var jobRepository          = new JobRepository();
            var jobItemRepository      = new JobItemRepository();
            var listItemRepository     = new ListItemRepository();
            var entityIdProvider       = new DirectEntityIdProvider();
            var instrumentRepository   = new InstrumentRepository();
            var deliveryRepository     = new DeliveryRepository();
            var deliveryItemRepository = new DeliveryItemRepository();

            var customerId1 = Guid.NewGuid();
            var customerId2 = Guid.NewGuid();
            var job1Id      = Guid.NewGuid();
            var job2Id      = Guid.NewGuid();
            var job3Id      = Guid.NewGuid();
            var jobItem1Id  = Guid.NewGuid();
            var jobItem2Id  = Guid.NewGuid();
            var jobItem3Id  = Guid.NewGuid();
            var jobItem4Id  = Guid.NewGuid();
            var jobItem5Id  = Guid.NewGuid();
            var jobItem6Id  = Guid.NewGuid();
            var jobItem7Id  = Guid.NewGuid();
            var jobItem8Id  = Guid.NewGuid();
            var jobItem9Id  = Guid.NewGuid();

            CreateDeliveriesFromPendingItemsHelper.CreateContextForPendingItemTests(
                customerId1, customerId2, job1Id, job2Id, job3Id, jobItem1Id, jobItem2Id, jobItem3Id, jobItem4Id, jobItem5Id, jobItem6Id, jobItem7Id, jobItem8Id, jobItem9Id);

            var deliveryItemService =
                new DeliveryItemService(
                    userContext, deliveryRepository, deliveryItemRepository, jobItemRepository, quoteItemRepository, listItemRepository, customerRepository, dispatcher);
            var deliveryService = new DeliveryService(userContext, deliveryRepository, deliveryItemService, customerRepository, entityIdProvider, dispatcher);

            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem1Id, customerId1, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem2Id, customerId1, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem3Id, customerId1, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem4Id, customerId1, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem5Id, customerId1, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem6Id, customerId1, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem7Id, customerId1, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem8Id, customerId2, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem9Id, customerId2, "some notes");
            deliveryService.CreateDeliveriesFromPendingItems();

            var deliveries = deliveryService.GetDeliveries().ToList();

            Assert.AreEqual(2, deliveries.Count);
            var deliveryItems = deliveryItemService.GetDeliveryItems(deliveries[0].Id).ToList();

            Assert.AreEqual(7, deliveryItems.Count);
        }
Ejemplo n.º 11
0
        public RatesService(InstrumentRepository instrumentRepository, Protocol protocol)
        {
            m_instrumentRepository = instrumentRepository;
            m_protocol             = protocol;

            Receive <OneSecondElapsed>(e => Handle(e));
            Receive <InstrumentsRequest>(c => GetInstrumentNames(c));
        }
Ejemplo n.º 12
0
 public async Task <List <Instrument> > GetAllAsync()
 {
     using (var instruments = new InstrumentRepository())
     {
         return(await(from instrument in instruments.GetAll()
                      select instrument).ToListAsync());
     }
 }
        private async void OpdaterInstrumentBtn_Click(object sender, EventArgs e)
        {
            bool                 opdaterFejl    = false;
            string               fejlMeddelelse = string.Empty;
            KonverterValidator   k                   = new KonverterValidator();
            InstrumentRepository instRep             = new InstrumentRepository();
            Instrument           opdateretInstrument = new Instrument();

            //Sætter properties som er string og derfor kun skal valideres på indhold i repository
            opdateretInstrument.VareNummer  = instrument.VareNummer;
            opdateretInstrument.Navn        = InstrumentNavnTxt.Text;
            opdateretInstrument.Beskrivelse = InstrumentBeskrivelseTxt.Text;
            opdateretInstrument.Producent   = ProducentCombo.SelectedItem.ToString();
            opdateretInstrument.VareGruppe  = gruppeId;
            //Der valideres på om der er problemer med at konvertere de modtagne input til de nødvendige datatyper..
            //Er der et problem med konvertering lagres en fejlmeddelelse og opdaterfejl sættes til true.
            opdateretInstrument.IndkøbsPris = k.DoubleConverter(InstrumentIndkøbsPrisTxt.Text);
            if (opdateretInstrument.IndkøbsPris == 0)
            {
                opdaterFejl     = true;
                fejlMeddelelse += "Indkøbspris var ikke et tal";
            }
            opdateretInstrument.Fortjeneste = k.DoubleConverter(InstrumentFortjenesteTxt.Text);
            if (opdateretInstrument.Fortjeneste == 0)
            {
                opdaterFejl     = true;
                fejlMeddelelse += "Indkøbspris var ikke et tal";
            }
            opdateretInstrument.LagerDato = k.DateTimeConverter(InstrumentLagerDato.Text);
            if (opdateretInstrument.LagerDato == new DateTime(1, 1, 1))
            {
                opdaterFejl     = true;
                fejlMeddelelse += "Lagerdato var ikke en dato";
            }
            opdateretInstrument.Antal = k.IntConverter(InstrumentAntalTxt.Text);
            if (opdateretInstrument.Antal == 0)
            {
                opdaterFejl     = true;
                fejlMeddelelse += "Antal var ikke et tal";
            }
            if (opdaterFejl == false)
            {
                if (await instRep.OpdaterInstrumentAsync(opdateretInstrument))
                {
                    this.Hide();
                    prevForm.Show();
                    prevForm.LoadInstrumentGrid();
                }
                else
                {
                    StatusLabel.Text = "Der var problemer ved eksekvering mod databasen";
                }
            }
            else
            {
                StatusLabel.Text = fejlMeddelelse;
            }
        }
Ejemplo n.º 14
0
 public async Task <Instrument> FindByIdAsync(int id)
 {
     using (var instruments = new InstrumentRepository())
     {
         return(await(from instrument in instruments.GetAll()
                      where instrument.Id == id
                      select instrument).FirstAsync());
     }
 }
        public void GetByIdTest()
        {
            InstrumentRepository repo       = new InstrumentRepository();
            C_Instrument         instrument = repo.GetById(1);

            Assert.IsNotNull(instrument);
            Assert.IsNotNull(instrument.Name);
            Assert.IsNotNull(instrument.Description);
            Assert.IsNotNull(instrument.IconUrl);
        }
        private void GetInstruments()
        {
            Instruments = new ReactiveList <Instrument>();

            var instrumentRepo = new InstrumentRepository(DbContext);
            var instrumentList = instrumentRepo.FindInstruments().Result;

            foreach (Instrument i in instrumentList)
            {
                Instruments.Add(i);
            }
        }
Ejemplo n.º 17
0
        private void BtnClearCount_Click(object sender, System.EventArgs e)
        {
            var instrumentRepository = new InstrumentRepository();
            var instruments          = instrumentRepository.Get();

            foreach (var instrument in instruments)
            {
                instrumentRepository.Delete(instrument);
            }

            instrumentRepository.AddDefaultInstrument();
        }
Ejemplo n.º 18
0
        public void RefreshCollections()
        {
            Tags.Clear();
            Instruments.Clear();

            using (var context = new MyDBContext())
            {
                Tags.AddRange(context.Tags.ToList());

                var im = new InstrumentRepository(context);
                Instruments.AddRange(im.FindInstruments().Result);
            }
        }
Ejemplo n.º 19
0
        public void AddInstrument_AddNull_ThrowException()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new LibraryContext(options);
            IInstrumentRepository instrumentRepository = new InstrumentRepository(context);

            //Act & Assert
            Assert.ThrowsException <ArgumentNullException>(() => instrumentRepository.Add(null));
        }
Ejemplo n.º 20
0
        private async void LoadInstrumentGrid()
        {
            //Instanciere repository med henblik på at læse instrumentgrupper ind i datagridview
            InstrumentRepository rep = new InstrumentRepository();

            //nulstiller datasource
            InstrumentGrpGrid.DataSource = null;
            //loader instrumentgrupper ind med metode fra repository
            List <Instrument> instrumenter = await rep.HentInstrumenterAsync(valgtVareGruppeId);

            //Lister instrumentgrupperne ved at sætte listen af instrumentgrupper som datasource på instrumentgrpgrid
            InstrumentGrpGrid.DataSource = instrumenter;
        }
Ejemplo n.º 21
0
        private void RunFilterCommand()
        {
            var(instruments, messageToScreen) = InstrumentRepository.GetFilteredInstruments(SelectedInstrumentViewModel.ItemType);

            if (instruments == null)
            {
                MessageToScreen = messageToScreen;
            }
            else
            {
                UpdateInstrument(instruments);
            }
            MessageToScreen = messageToScreen;
        }
Ejemplo n.º 22
0
        private void InitDatabase()
        {
            var(instruments, messageToScreen) = InstrumentRepository.GetAllInstruments();

            if (instruments == null)
            {
                MessageToScreen = messageToScreen;
            }
            else
            {
                UpdateInstrument(instruments);
                MessageToScreen = messageToScreen;
            }
        }
Ejemplo n.º 23
0
        public void UpdateInstrument_ProvidingNonExistingCategory_ThrowException()
        {
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new LibraryContext(options);
            IInstrumentRepository instrumentRepository = new InstrumentRepository(context);

            var instru = new InstrumentTO {
                Name = "Saxophone"
            };

            //Act & Assert
            Assert.ThrowsException <ArgumentException>(() => instrumentRepository.Update(instru));
        }
Ejemplo n.º 24
0
        private void ExecuteAddSelectedInstruments(IList selectedInstruments)
        {
            if (selectedInstruments == null)
            {
                throw new ArgumentNullException(nameof(selectedInstruments));
            }
            if (selectedInstruments.Count == 0)
            {
                return;
            }

            var instrumentSource = new InstrumentRepository(DbContext);

            var count = selectedInstruments.Cast <Instrument>().Count(newInstrument => TryAddInstrument(instrumentSource, newInstrument));

            Status = $"{count}/{selectedInstruments.Count} instruments added.";
        }
Ejemplo n.º 25
0
        private async void SletInstrumentBtn_Click(object sender, EventArgs e)
        {
            //Instanciere object til at slette instrument
            InstrumentRepository sletInstrument = new InstrumentRepository();
            //Kalder sletinstrument metoden på sletinstrument objektet og passer varenummeret på varen der skal slettes
            bool successfuldSlet = await sletInstrument.SletInstrumentAsync(valgtInstrumentVareNummer);

            //Der udskrives fejlmeddelelse alt efter hvorvidt det har ladet sig gøre at slette instrument og grid over instrumenter reloades
            if (successfuldSlet)
            {
                StatusLabel.Text = "Du har successfuldt slettet vare";
                LoadInstrumentGrid();
            }
            else
            {
                StatusLabel.Text = "Der opstod en fejl ved sletning af vare";
            }
        }
Ejemplo n.º 26
0
        private bool TryAddInstrument(InstrumentRepository instrumentSource, Instrument newInstrument, bool showDialogs = true)
        {
            try
            {
                if (instrumentSource.AddInstrument(newInstrument) != null)
                {
                    AddedInstruments.Add(newInstrument);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                if (showDialogs)
                {
                    _dialogService.ShowMessageAsync(this, "Error", ex.Message);
                }

                _logger.Log(NLog.LogLevel.Warn, ex, "Error adding instrument");
            }
            return(false);
        }
        public static void CreateContext(Guid testStandardId, Guid jobItemId)
        {
            var dispatcher     = MockRepository.GenerateMock <IQueueDispatcher <IMessage> >();
            var userRepository = new UserAccountRepository();
            var user           = userRepository.GetByEmail("*****@*****.**", false);
            var userContext    = new TestUserContext(user);

            var companyDetailsRepository = new CompanyDetailsRepository();
            var quoteRepository          = new QuoteRepository();
            var quoteItemRepository      = new QuoteItemRepository();
            var customerRepository       = new CustomerRepository();
            var jobRepository            = new JobRepository();
            var jobItemRepository        = new JobItemRepository();
            var listItemRepository       = new ListItemRepository();
            var entityIdProvider         = new DirectEntityIdProvider();
            var instrumentRepository     = new InstrumentRepository();

            var instrumentId      = Guid.NewGuid();
            var instrumentService = new InstrumentService(userContext, instrumentRepository, dispatcher);

            instrumentService.Create(instrumentId, "Druck", "DPI601IS", "None", "Description", 15);

            var customerId      = Guid.NewGuid();
            var customerService = new CustomerService(userContext, customerRepository, dispatcher);

            customerService.Create(customerId, "Gael Ltd", String.Empty, new Address(), new ContactInfo(), "Gael Ltd", new Address(), new ContactInfo(), "Gael Ltd", new Address(), new ContactInfo());

            var listItemService = new ListItemService(userContext, listItemRepository, dispatcher);
            var jobService      = new JobService(userContext, null, jobRepository, listItemRepository, customerRepository, entityIdProvider, dispatcher);
            var jobItemService  = new JobItemService(userContext, jobRepository, jobItemRepository, listItemService, instrumentService, dispatcher);

            var jobId = Guid.NewGuid();

            jobService.CreateJob(jobId, "Some instructions", "PO1000", "AD1000", listItemService.GetAllByCategory(ListItemCategoryType.JobType).First().Id, customerId, "some notes", "job contact");
            jobItemService.CreateJobItem(
                jobId, jobItemId, instrumentId, "12345", String.Empty,
                listItemService.GetAllByCategory(ListItemCategoryType.JobItemInitialStatus).First().Id,
                listItemService.GetAllByCategory(ListItemCategoryType.JobItemCategory).First().Id,
                12, "instructions", String.Empty, false, String.Empty, String.Empty);
        }
Ejemplo n.º 28
0
        public void AddInstrument_Successful()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new LibraryContext(options);
            IInstrumentRepository instrumentRepository = new InstrumentRepository(context);

            //Act
            var instru = new InstrumentTO {
                Name = "Saxophone"
            };
            var result = instrumentRepository.Add(instru);

            context.SaveChanges();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Name, "Saxophone");
        }
Ejemplo n.º 29
0
        private async void OpdaterInstrumentBtn_Click(object sender, EventArgs e)
        {
            //Instanciere instrument repository med henblik på at kunne hente et instrument med valgt instrument varenummer
            InstrumentRepository hentInstrument = new InstrumentRepository();
            //Henter instrument ned og lagre i valgtinstrument variablen
            Instrument valgtInstrument = await hentInstrument.HentInstrumentAsync(valgtInstrumentVareNummer);

            //Har den ikke returneret null kan opdatering af instrument påbegyndes
            if (valgtInstrument != null)
            {
                //instanciere en opdateringsform som modtager instrumentet der skal opdateres/redigere samt den nuværende form
                OpdaterInstrumentForm opdaterForm = new OpdaterInstrumentForm(this, valgtInstrument, gruppeId);
                //skjuler denne form og viser opdateringsformen
                this.Hide();
                opdaterForm.Show();
            }
            else
            {
                //modtog den ikke noget instrument (null) udskrives en fejlmeddelelse
                StatusLabel.Text = "Kunne ikke finde den pågældende varer";
            }
        }
Ejemplo n.º 30
0
        private bool TryAddInstrument(InstrumentRepository instrumentSource,
                                      Instrument newInstrument, bool showDialogs = true)
        {
            try
            {
                if (instrumentSource.AddInstrument(newInstrument).Result.ID != 0)
                {
                    //if (AddedInstruments.Contains(newInstrument)) return false;

                    AddedInstruments.Add(newInstrument);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                if (showDialogs)
                {
                    dialogService.ShowMessageAsync(this, "Error", ex.Message);
                }

                Logger.Log(LogLevel.Warn, ex, "Error adding instrument");
            }
            return(false);
        }