コード例 #1
0
ファイル: Data.cs プロジェクト: bgillikin/ResistorCalculator
        private static void InitData()
        {
            // get dictionary of all avaiable bands and their specification from the web service
            // this is done first so we can use them with the entries data
            ResistorCalculatorService.ResistorCalculatorServiceClient service    = new ResistorCalculatorService.ResistorCalculatorServiceClient();
            Dictionary <int, ResistorCalculatorService.BandDetail>    bandColors = service.GetBandList();
            List <Band> bands = new List <Band>();

            foreach (KeyValuePair <int, ResistorCalculatorService.BandDetail> band in bandColors)
            {
                ResistorCalculatorService.BandDetail bandItem = (ResistorCalculatorService.BandDetail)band.Value;
                Band bandColor = new Band(band.Key, bandItem);
                bands.Add(bandColor);
            }

            // get dictionary of all avaiable bands and their specification from the web service
            Dictionary <int, ResistorCalculatorService.EntryDetail> entryList = service.GetEntryList();
            List <Entry> entries = new List <Entry>();

            foreach (KeyValuePair <int, ResistorCalculatorService.EntryDetail> entry in entryList)
            {
                ResistorCalculatorService.EntryDetail entryItem = (ResistorCalculatorService.EntryDetail)entry.Value;
                Entry entryData = new Entry(entryItem.ID, entryItem);
                entries.Add(entryData);
            }

            // set the static lists
            Bands   = bands;
            Entries = entries;
        }
コード例 #2
0
        public ActionResult AddEditPost(string id, string date, string band1, string band2, string band3, string band4, string notes)
        {
            // seperate the defined values for each band from their ids
            int    band1ID    = Convert.ToInt32(band1.Split('|')[0]);
            int    band2ID    = Convert.ToInt32(band2.Split('|')[0]);
            int    band3ID    = Convert.ToInt32(band3.Split('|')[0]);
            int    band4ID    = Convert.ToInt32(band4.Split('|')[0]);
            string first      = band1.Split('|')[1];
            string second     = band2.Split('|')[1];
            double multiplier = Convert.ToDouble(band3.Split('|')[1]);
            double tolerance  = Convert.ToDouble(band4.Split('|')[1]);

            // calculate the resistance and its range from the tolerance
            ResistorCalculatorService.ResistorCalculatorServiceClient service = new ResistorCalculatorService.ResistorCalculatorServiceClient();
            var resistance = service.CalculateResistance(first, second, multiplier, tolerance);

            // check if this is for an existing entry and therefore and update not an add
            Entry entry = new Entry(Convert.ToInt32(id), Convert.ToDateTime(date), band1ID, band2ID, band3ID, band4ID, resistance, notes);

            if (Convert.ToInt32(id) > 0)
            {
                _entriesRepository.UpdateEntry(entry);
            }
            else
            {
                _entriesRepository.AddEntry(entry);
            }

            return(RedirectToAction("ViewDelete"));
        }
コード例 #3
0
        public void SaveEntryList()
        {
            // Arrange
            ResistorCalculatorService.ResistorCalculatorServiceClient service = new ResistorCalculatorService.ResistorCalculatorServiceClient();

            // Act
            // get the original entry list
            Dictionary <int, ResistorCalculatorService.EntryDetail> entryList = service.GetEntryList();

            // build an new list of just the entry detail adn save back to service
            List <ResistorCalculatorService.EntryDetail> entries = new List <ResistorCalculatorService.EntryDetail>();

            foreach (KeyValuePair <int, ResistorCalculatorService.EntryDetail> entry in entryList)
            {
                ResistorCalculatorService.EntryDetail entryDetail = entry.Value;
                entries.Add(entryDetail);
            }
            service.SaveEntryList(entries.ToArray());

            // get the updated entry list post save to service
            Dictionary <int, ResistorCalculatorService.EntryDetail> entryList2 = service.GetEntryList();

            // Assert
            Assert.AreEqual(entryList.Count, entryList2.Count);
        }
コード例 #4
0
        public void GetEntryList()
        {
            // Arrange
            ResistorCalculatorService.ResistorCalculatorServiceClient service = new ResistorCalculatorService.ResistorCalculatorServiceClient();

            // Act
            Dictionary <int, ResistorCalculatorService.EntryDetail> entryList = service.GetEntryList();

            // Assert
            Assert.AreEqual(entryList.Count, entryList.Last().Key);
        }
コード例 #5
0
        public void GetBandList()
        {
            // Arrange
            ResistorCalculatorService.ResistorCalculatorServiceClient service = new ResistorCalculatorService.ResistorCalculatorServiceClient();

            // Act
            Dictionary <int, ResistorCalculatorService.BandDetail> bandList = service.GetBandList();

            // Assert
            Assert.AreEqual(bandList.Count, 14);
        }
コード例 #6
0
ファイル: Data.cs プロジェクト: bgillikin/ResistorCalculator
        public static void SaveEntryData()
        {
            // build a list of only the entry detail data objects
            List <ResistorCalculatorService.EntryDetail> entryList = new List <ResistorCalculatorService.EntryDetail>();

            foreach (Entry entry in Entries)
            {
                entryList.Add(entry.EntryData);
            }

            // save all the entry detail data from the list thru the service
            ResistorCalculatorService.ResistorCalculatorServiceClient service = new ResistorCalculatorService.ResistorCalculatorServiceClient();
            service.SaveEntryList(entryList.ToArray());
        }
コード例 #7
0
        public void CalculateResistance()
        {
            // Arrange
            ResistorCalculatorService.ResistorCalculatorServiceClient service = new ResistorCalculatorService.ResistorCalculatorServiceClient();

            // Act
            // calculate the resitance locally for Red - Violet - Green - Brown
            double rootValue       = 27 * 100000;
            double resistanceMin   = rootValue * (.99);
            double resistanceMax   = rootValue * (1.01);
            string resistanceLocal = resistanceMin.ToString() + " - " + resistanceMax.ToString();

            // calculate the resistance from the service by their values Red(2) - Violet(7) - Green(100000) - Brown(.01)
            string resistanceService = service.CalculateResistance("2", "7", 100000, .01);

            // Assert
            Assert.AreEqual(resistanceLocal, resistanceService);
        }