示例#1
0
        public void UpdateTest()
        {
            this._context = this.InitContext().Result;
            ProcessorService ps = new ProcessorService(this._context);
            Processor        p1 = new Processor()
            {
                id            = "0",
                name          = "test_processor1",
                version       = "0.0.1",
                enabled       = true,
                description   = "test processor1",
                file_type     = ".fake",
                process_found = 1
            };
            Processor p2 = new Processor()
            {
                id            = "0",
                name          = "test_processor2",
                version       = "0.0.2",
                enabled       = true,
                description   = "test processor2",
                file_type     = ".fake2",
                process_found = 1
            };

            this._context.Processors.AddAsync(p1);
            this._context.SaveChangesAsync();

            var t      = ps.Update(p1.id, p2);
            var result = this._context.Processors.SingleAsync(p => p.id == p1.id).Result;

            Assert.Equal(p2.name, result.name);             // P1 processor updated with P2

            var t2      = ps.Update("invalid", p1);
            var result2 = this._context.Processors.SingleAsync(p => p.id == p1.id).Result;

            Assert.Equal(p2.name, result2.name);            // No update expected.
        }
示例#2
0
        public void UpdateListTest()
        {
            this._context = this.InitContext().Result;
            ProcessorService ps = new ProcessorService(this._context);
            Processor        p1 = new Processor()
            {
                id            = "0",
                name          = "test_processor1",
                version       = "0.0.1",
                enabled       = true,
                description   = "test processor1",
                file_type     = ".fake",
                process_found = 1
            };
            Processor p2 = new Processor()
            {
                id            = "1",
                name          = "test_processor2",
                version       = "0.0.1",
                enabled       = true,
                description   = "test processor2",
                file_type     = ".fake",
                process_found = 1
            };

            this._context.Processors.AddAsync(p1);
            this._context.Processors.AddAsync(p2);
            this._context.SaveChangesAsync();

            p1.file_type = ".very_fake1";
            p2.file_type = ".very_fake2";
            Processor[] pList = new Processor[] { p1, p2 };

            var t       = ps.Update(pList);
            var result1 = this._context.Processors.SingleAsync(p => p.id == p1.id).Result;

            Assert.Equal(p1.file_type, result1.file_type);

            var result2 = this._context.Processors.SingleAsync(p => p.id == p2.id).Result;

            Assert.Equal(p2.file_type, result2.file_type);
        }