Datei: IntegrationTests/IntegrationTests/CompositePartListTests.cs
Last Commit (9d1552b)
| 1 | // |
| 2 | // Copyright (c) 2002-2016 Mirko Matytschak |
| 3 | // (www.netdataobjects.de) |
| 4 | // |
| 5 | // Author: Mirko Matytschak |
| 6 | // |
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
| 9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
| 11 | // conditions: |
| 12 | |
| 13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
| 14 | // of the Software. |
| 15 | // |
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | // DEALINGS IN THE SOFTWARE. |
| 21 | |
| 22 | |
| 23 | using System; |
| 24 | using System.Collections.Generic; |
| 25 | using System.Text; |
| 26 | using NUnit.Framework; |
| 27 | using PureBusinessClasses; |
| 28 | using NDO; |
| 29 | using NDO.Mapping; |
| 30 | using NDO.Query; |
| 31 | |
| 32 | namespace NdoUnitTests |
| 33 | { |
| 34 | ····[TestFixture] |
| 35 | public class CompositePartListTests |
| 36 | ····{ |
| 37 | ········[SetUp] |
| 38 | ········public void Setup() |
| 39 | ········{ |
| 40 | ········} |
| 41 | |
| 42 | ········[TearDown] |
| 43 | ········public void TearDown() |
| 44 | ········{ |
| 45 | ············var pm = PmFactory.NewPersistenceManager(); |
| 46 | ············pm.Delete(pm.GetClassExtent(typeof(SnmpDevice))); |
| 47 | ············pm.Save(); |
| 48 | ············pm.Delete(pm.GetClassExtent(typeof(Device))); |
| 49 | ············pm.Save(); |
| 50 | ············pm.Dispose(); |
| 51 | ········} |
| 52 | |
| 53 | ········[Test] |
| 54 | ········public void TestBaseOnly() |
| 55 | ········{ |
| 56 | ············var pm = PmFactory.NewPersistenceManager(); |
| 57 | ············Device root = new Device(); |
| 58 | ············root.Name = "root"; |
| 59 | ············pm.MakePersistent(root); |
| 60 | ············pm.Save(); |
| 61 | |
| 62 | ············Device child1 = root.NewDevice(typeof(Device)); |
| 63 | ············child1.Name = "1"; |
| 64 | |
| 65 | ············Device child2 = root.NewDevice(typeof(Device)); |
| 66 | ············child2.Name = "2"; |
| 67 | |
| 68 | ············pm.Save(); |
| 69 | |
| 70 | ············Device child11 = child1.NewDevice(typeof(Device)); |
| 71 | ············child11.Name = "11"; |
| 72 | |
| 73 | ············Device child12 = child1.NewDevice(typeof(Device)); |
| 74 | ············child12.Name = "12"; |
| 75 | |
| 76 | ············Device child21 = child2.NewDevice(typeof(Device)); |
| 77 | ············child21.Name = "21"; |
| 78 | |
| 79 | ············Device child22 = child2.NewDevice(typeof(Device)); |
| 80 | ············child22.Name = "22"; |
| 81 | |
| 82 | ············pm.Save(); |
| 83 | |
| 84 | ············NDOQuery<Device> q = new NDOQuery<Device>(pm); |
| 85 | ············decimal c = (decimal)q.ExecuteAggregate("name", AggregateType.Count); |
| 86 | |
| 87 | ············Assert.That(7m ==··c, "Count wrong: "); |
| 88 | |
| 89 | ············q = new NDOQuery<Device>(pm, "name = {0}"); |
| 90 | ············q.Parameters.Add("root"); |
| 91 | |
| 92 | ············root = q.ExecuteSingle(true); |
| 93 | |
| 94 | ············Assert.That(2 ==··root.Subdevices.Count, "Child Count wrong #1: "); |
| 95 | ············foreach (Device d in root.Subdevices) |
| 96 | ············{ |
| 97 | ················Assert.That(d.Name == "1" || d.Name == "2", "Name wrong #1"); |
| 98 | ············} |
| 99 | |
| 100 | ············pm.Delete(root); |
| 101 | ············pm.Save(); |
| 102 | ············pm.UnloadCache(); |
| 103 | |
| 104 | ············q = new NDOQuery<Device>(pm); |
| 105 | ············c = (decimal)q.ExecuteAggregate("name", AggregateType.Count); |
| 106 | ············Assert.That(0m ==··c, "Count wrong: "); |
| 107 | |
| 108 | ········} |
| 109 | |
| 110 | |
| 111 | ········[Test] |
| 112 | ········public void TestDerivedOnly() |
| 113 | ········{ |
| 114 | ············var pm = PmFactory.NewPersistenceManager(); |
| 115 | ············Device root = new SnmpDevice(); |
| 116 | ············root.Name = "root"; |
| 117 | ············pm.MakePersistent(root); |
| 118 | ············pm.Save(); |
| 119 | |
| 120 | ············Device child1 = root.NewDevice(typeof(SnmpDevice)); |
| 121 | ············child1.Name = "1"; |
| 122 | |
| 123 | ············Device child2 = root.NewDevice(typeof(SnmpDevice)); |
| 124 | ············child2.Name = "2"; |
| 125 | |
| 126 | ············pm.Save(); |
| 127 | |
| 128 | ············Device child11 = child1.NewDevice(typeof(SnmpDevice)); |
| 129 | ············child11.Name = "11"; |
| 130 | |
| 131 | ············Device child12 = child1.NewDevice(typeof(SnmpDevice)); |
| 132 | ············child12.Name = "12"; |
| 133 | |
| 134 | ············Device child21 = child2.NewDevice(typeof(SnmpDevice)); |
| 135 | ············child21.Name = "21"; |
| 136 | |
| 137 | ············Device child22 = child2.NewDevice(typeof(SnmpDevice)); |
| 138 | ············child22.Name = "22"; |
| 139 | |
| 140 | ············pm.Save(); |
| 141 | |
| 142 | ············NDOQuery<Device> q = new NDOQuery<Device>(pm); |
| 143 | ············decimal c = (decimal)q.ExecuteAggregate(AggregateType.Count);··// COUNT (*) FROM... |
| 144 | |
| 145 | ············Assert.That(7m ==··c, "Count wrong: "); |
| 146 | |
| 147 | ············q = new NDOQuery<Device>(pm, "name = {0}"); |
| 148 | ············q.Parameters.Add("root"); |
| 149 | |
| 150 | ············root = q.ExecuteSingle(true); |
| 151 | |
| 152 | ············Assert.That(2 ==··root.Subdevices.Count, "Child Count wrong #1: "); |
| 153 | ············foreach (Device d in root.Subdevices) |
| 154 | ············{ |
| 155 | ················Assert.That(d.Name == "1" || d.Name == "2", "Name wrong #1"); |
| 156 | ············} |
| 157 | |
| 158 | ············pm.Delete(root); |
| 159 | ············pm.Save(); |
| 160 | ············pm.UnloadCache(); |
| 161 | |
| 162 | ············q = new NDOQuery<Device>(pm); |
| 163 | ············c = (decimal)q.ExecuteAggregate("name", AggregateType.Count); |
| 164 | ············Assert.That(0 ==··c, "Count wrong: "); |
| 165 | ········} |
| 166 | |
| 167 | |
| 168 | ········[Test] |
| 169 | ········public void TestMixed() |
| 170 | ········{ |
| 171 | ············var pm = PmFactory.NewPersistenceManager(); |
| 172 | ············Device root = new Device(); |
| 173 | ············root.Name = "root"; |
| 174 | ············pm.MakePersistent(root); |
| 175 | ············pm.Save(); |
| 176 | |
| 177 | ············Device child1 = root.NewDevice(typeof(SnmpDevice)); |
| 178 | ············child1.Name = "1"; |
| 179 | |
| 180 | ············Device child2 = root.NewDevice(typeof(Device)); |
| 181 | ············child2.Name = "2"; |
| 182 | |
| 183 | ············pm.Save(); |
| 184 | |
| 185 | ············Device child11 = child1.NewDevice(typeof(Device)); |
| 186 | ············child11.Name = "11"; |
| 187 | |
| 188 | ············Device child12 = child1.NewDevice(typeof(SnmpDevice)); |
| 189 | ············child12.Name = "12"; |
| 190 | |
| 191 | ············Device child21 = child2.NewDevice(typeof(Device)); |
| 192 | ············child21.Name = "21"; |
| 193 | |
| 194 | ············Device child22 = child2.NewDevice(typeof(SnmpDevice)); |
| 195 | ············child22.Name = "22"; |
| 196 | |
| 197 | ············pm.Save(); |
| 198 | |
| 199 | ············NDOQuery<Device> q = new NDOQuery<Device>(pm); |
| 200 | ············decimal c = (decimal)q.ExecuteAggregate("name", AggregateType.Count); |
| 201 | |
| 202 | ············Assert.That(7m ==··c, "Count wrong: "); |
| 203 | |
| 204 | ············q = new NDOQuery<Device>(pm, "name = {0}"); |
| 205 | ············q.Parameters.Add("root"); |
| 206 | |
| 207 | ············root = q.ExecuteSingle(true); |
| 208 | |
| 209 | ············Assert.That(2 ==··root.Subdevices.Count, "Child Count wrong #1: "); |
| 210 | ············foreach (Device d in root.Subdevices) |
| 211 | ············{ |
| 212 | ················Assert.That(d.Name == "1" || d.Name == "2", "Name wrong #1"); |
| 213 | ············} |
| 214 | |
| 215 | ············pm.Delete(root); |
| 216 | ············pm.Save(); |
| 217 | ············pm.UnloadCache(); |
| 218 | |
| 219 | ············q = new NDOQuery<Device>(pm); |
| 220 | ············c = (decimal)q.ExecuteAggregate("name", AggregateType.Count); |
| 221 | ············Assert.That(0m ==··c, "Count wrong: "); |
| 222 | ········} |
| 223 | |
| 224 | |
| 225 | ········[Test] |
| 226 | ········public void TestMapping() |
| 227 | ········{ |
| 228 | ············var pm = PmFactory.NewPersistenceManager(); |
| 229 | ············Class cl = pm.NDOMapping.FindClass(typeof(Device)); |
| 230 | ············Relation r = cl.FindRelation("subdevices"); |
| 231 | ············Assert.That(r.Bidirectional == false, "Relation shouldn't be bidirectional #1"); |
| 232 | ············Assert.That(r.ForeignRelation == null, "No foreign Relation should appear #1"); |
| 233 | ············cl = pm.NDOMapping.FindClass(typeof(SnmpDevice)); |
| 234 | ············r = cl.FindRelation("subdevices"); |
| 235 | ············Assert.That(r.Bidirectional == false, "Relation shouldn't be bidirectional #1"); |
| 236 | ············Assert.That(r.ForeignRelation == null, "No foreign Relation should appear #1"); |
| 237 | ········} |
| 238 | |
| 239 | ····} |
| 240 | } |
| 241 |
New Commit (60cb179)
| 1 | // |
| 2 | // Copyright (c) 2002-2016 Mirko Matytschak |
| 3 | // (www.netdataobjects.de) |
| 4 | // |
| 5 | // Author: Mirko Matytschak |
| 6 | // |
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
| 9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
| 11 | // conditions: |
| 12 | |
| 13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
| 14 | // of the Software. |
| 15 | // |
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | // DEALINGS IN THE SOFTWARE. |
| 21 | |
| 22 | |
| 23 | using System; |
| 24 | using System.Collections.Generic; |
| 25 | using System.Text; |
| 26 | using NUnit.Framework; |
| 27 | using PureBusinessClasses; |
| 28 | using NDO; |
| 29 | using NDO.Mapping; |
| 30 | using NDO.Query; |
| 31 | |
| 32 | namespace NdoUnitTests |
| 33 | { |
| 34 | ····[TestFixture] |
| 35 | public class CompositePartListTests : NDOTest |
| 36 | ····{ |
| 37 | ········[SetUp] |
| 38 | ········public void Setup() |
| 39 | ········{ |
| 40 | ········} |
| 41 | |
| 42 | ········[TearDown] |
| 43 | ········public void TearDown() |
| 44 | ········{ |
| 45 | ············var pm = PmFactory.NewPersistenceManager(); |
| 46 | ············pm.Delete(pm.GetClassExtent(typeof(SnmpDevice))); |
| 47 | ············pm.Save(); |
| 48 | ············pm.Delete(pm.GetClassExtent(typeof(Device))); |
| 49 | ············pm.Save(); |
| 50 | ············pm.Dispose(); |
| 51 | ········} |
| 52 | |
| 53 | ········[Test] |
| 54 | ········public void TestBaseOnly() |
| 55 | ········{ |
| 56 | ············var pm = PmFactory.NewPersistenceManager(); |
| 57 | ············Device root = new Device(); |
| 58 | ············root.Name = "root"; |
| 59 | ············pm.MakePersistent(root); |
| 60 | ············pm.Save(); |
| 61 | |
| 62 | ············Device child1 = root.NewDevice(typeof(Device)); |
| 63 | ············child1.Name = "1"; |
| 64 | |
| 65 | ············Device child2 = root.NewDevice(typeof(Device)); |
| 66 | ············child2.Name = "2"; |
| 67 | |
| 68 | ············pm.Save(); |
| 69 | |
| 70 | ············Device child11 = child1.NewDevice(typeof(Device)); |
| 71 | ············child11.Name = "11"; |
| 72 | |
| 73 | ············Device child12 = child1.NewDevice(typeof(Device)); |
| 74 | ············child12.Name = "12"; |
| 75 | |
| 76 | ············Device child21 = child2.NewDevice(typeof(Device)); |
| 77 | ············child21.Name = "21"; |
| 78 | |
| 79 | ············Device child22 = child2.NewDevice(typeof(Device)); |
| 80 | ············child22.Name = "22"; |
| 81 | |
| 82 | ············pm.Save(); |
| 83 | |
| 84 | ············NDOQuery<Device> q = new NDOQuery<Device>(pm); |
| 85 | ············decimal c = (decimal)q.ExecuteAggregate("name", AggregateType.Count); |
| 86 | |
| 87 | ············Assert.That(7m ==··c, "Count wrong: "); |
| 88 | |
| 89 | ············q = new NDOQuery<Device>(pm, "name = {0}"); |
| 90 | ············q.Parameters.Add("root"); |
| 91 | |
| 92 | ············root = q.ExecuteSingle(true); |
| 93 | |
| 94 | ············Assert.That(2 ==··root.Subdevices.Count, "Child Count wrong #1: "); |
| 95 | ············foreach (Device d in root.Subdevices) |
| 96 | ············{ |
| 97 | ················Assert.That(d.Name == "1" || d.Name == "2", "Name wrong #1"); |
| 98 | ············} |
| 99 | |
| 100 | ············pm.Delete(root); |
| 101 | ············pm.Save(); |
| 102 | ············pm.UnloadCache(); |
| 103 | |
| 104 | ············q = new NDOQuery<Device>(pm); |
| 105 | ············c = (decimal)q.ExecuteAggregate("name", AggregateType.Count); |
| 106 | ············Assert.That(0m ==··c, "Count wrong: "); |
| 107 | |
| 108 | ········} |
| 109 | |
| 110 | |
| 111 | ········[Test] |
| 112 | ········public void TestDerivedOnly() |
| 113 | ········{ |
| 114 | ············var pm = PmFactory.NewPersistenceManager(); |
| 115 | ············Device root = new SnmpDevice(); |
| 116 | ············root.Name = "root"; |
| 117 | ············pm.MakePersistent(root); |
| 118 | ············pm.Save(); |
| 119 | |
| 120 | ············Device child1 = root.NewDevice(typeof(SnmpDevice)); |
| 121 | ············child1.Name = "1"; |
| 122 | |
| 123 | ············Device child2 = root.NewDevice(typeof(SnmpDevice)); |
| 124 | ············child2.Name = "2"; |
| 125 | |
| 126 | ············pm.Save(); |
| 127 | |
| 128 | ············Device child11 = child1.NewDevice(typeof(SnmpDevice)); |
| 129 | ············child11.Name = "11"; |
| 130 | |
| 131 | ············Device child12 = child1.NewDevice(typeof(SnmpDevice)); |
| 132 | ············child12.Name = "12"; |
| 133 | |
| 134 | ············Device child21 = child2.NewDevice(typeof(SnmpDevice)); |
| 135 | ············child21.Name = "21"; |
| 136 | |
| 137 | ············Device child22 = child2.NewDevice(typeof(SnmpDevice)); |
| 138 | ············child22.Name = "22"; |
| 139 | |
| 140 | ············pm.Save(); |
| 141 | |
| 142 | ············NDOQuery<Device> q = new NDOQuery<Device>(pm); |
| 143 | ············decimal c = (decimal)q.ExecuteAggregate(AggregateType.Count);··// COUNT (*) FROM... |
| 144 | |
| 145 | ············Assert.That(7m ==··c, "Count wrong: "); |
| 146 | |
| 147 | ············q = new NDOQuery<Device>(pm, "name = {0}"); |
| 148 | ············q.Parameters.Add("root"); |
| 149 | |
| 150 | ············root = q.ExecuteSingle(true); |
| 151 | |
| 152 | ············Assert.That(2 ==··root.Subdevices.Count, "Child Count wrong #1: "); |
| 153 | ············foreach (Device d in root.Subdevices) |
| 154 | ············{ |
| 155 | ················Assert.That(d.Name == "1" || d.Name == "2", "Name wrong #1"); |
| 156 | ············} |
| 157 | |
| 158 | ············pm.Delete(root); |
| 159 | ············pm.Save(); |
| 160 | ············pm.UnloadCache(); |
| 161 | |
| 162 | ············q = new NDOQuery<Device>(pm); |
| 163 | ············c = (decimal)q.ExecuteAggregate("name", AggregateType.Count); |
| 164 | ············Assert.That(0 ==··c, "Count wrong: "); |
| 165 | ········} |
| 166 | |
| 167 | |
| 168 | ········[Test] |
| 169 | ········public void TestMixed() |
| 170 | ········{ |
| 171 | ············var pm = PmFactory.NewPersistenceManager(); |
| 172 | ············Device root = new Device(); |
| 173 | ············root.Name = "root"; |
| 174 | ············pm.MakePersistent(root); |
| 175 | ············pm.Save(); |
| 176 | |
| 177 | ············Device child1 = root.NewDevice(typeof(SnmpDevice)); |
| 178 | ············child1.Name = "1"; |
| 179 | |
| 180 | ············Device child2 = root.NewDevice(typeof(Device)); |
| 181 | ············child2.Name = "2"; |
| 182 | |
| 183 | ············pm.Save(); |
| 184 | |
| 185 | ············Device child11 = child1.NewDevice(typeof(Device)); |
| 186 | ············child11.Name = "11"; |
| 187 | |
| 188 | ············Device child12 = child1.NewDevice(typeof(SnmpDevice)); |
| 189 | ············child12.Name = "12"; |
| 190 | |
| 191 | ············Device child21 = child2.NewDevice(typeof(Device)); |
| 192 | ············child21.Name = "21"; |
| 193 | |
| 194 | ············Device child22 = child2.NewDevice(typeof(SnmpDevice)); |
| 195 | ············child22.Name = "22"; |
| 196 | |
| 197 | ············pm.Save(); |
| 198 | |
| 199 | ············NDOQuery<Device> q = new NDOQuery<Device>(pm); |
| 200 | ············decimal c = (decimal)q.ExecuteAggregate("name", AggregateType.Count); |
| 201 | |
| 202 | ············Assert.That(7m ==··c, "Count wrong: "); |
| 203 | |
| 204 | ············q = new NDOQuery<Device>(pm, "name = {0}"); |
| 205 | ············q.Parameters.Add("root"); |
| 206 | |
| 207 | ············root = q.ExecuteSingle(true); |
| 208 | |
| 209 | ············Assert.That(2 ==··root.Subdevices.Count, "Child Count wrong #1: "); |
| 210 | ············foreach (Device d in root.Subdevices) |
| 211 | ············{ |
| 212 | ················Assert.That(d.Name == "1" || d.Name == "2", "Name wrong #1"); |
| 213 | ············} |
| 214 | |
| 215 | ············pm.Delete(root); |
| 216 | ············pm.Save(); |
| 217 | ············pm.UnloadCache(); |
| 218 | |
| 219 | ············q = new NDOQuery<Device>(pm); |
| 220 | ············c = (decimal)q.ExecuteAggregate("name", AggregateType.Count); |
| 221 | ············Assert.That(0m ==··c, "Count wrong: "); |
| 222 | ········} |
| 223 | |
| 224 | |
| 225 | ········[Test] |
| 226 | ········public void TestMapping() |
| 227 | ········{ |
| 228 | ············var pm = PmFactory.NewPersistenceManager(); |
| 229 | ············Class cl = pm.NDOMapping.FindClass(typeof(Device)); |
| 230 | ············Relation r = cl.FindRelation("subdevices"); |
| 231 | ············Assert.That(r.Bidirectional == false, "Relation shouldn't be bidirectional #1"); |
| 232 | ············Assert.That(r.ForeignRelation == null, "No foreign Relation should appear #1"); |
| 233 | ············cl = pm.NDOMapping.FindClass(typeof(SnmpDevice)); |
| 234 | ············r = cl.FindRelation("subdevices"); |
| 235 | ············Assert.That(r.Bidirectional == false, "Relation shouldn't be bidirectional #1"); |
| 236 | ············Assert.That(r.ForeignRelation == null, "No foreign Relation should appear #1"); |
| 237 | ········} |
| 238 | |
| 239 | ····} |
| 240 | } |
| 241 |