private IProp GenerateProp(DropTableRecordSubScheme record) { var scheme = _schemeService.GetScheme <PropScheme>(record.SchemeSid); var propClass = GetPropClass(scheme); switch (propClass) { case PropClass.Equipment: //TODO Вынести в отдельный метод. Чтобы можно было использовать в крафте. var power = _randomSource.RollEquipmentPower(record.MinPower, record.MaxPower); var equipment = _propFactory.CreateEquipment(scheme); equipment.Power = power; return(equipment); case PropClass.Resource: var rolledCount = _randomSource.RollResourceCount(record.MinCount, record.MaxCount); return(new Resource(scheme, rolledCount)); case PropClass.Concept: var propScheme = _schemeService.GetScheme <PropScheme>(record.Concept); return(new Concept(scheme, propScheme)); default: throw new ArgumentException($"Неизвестный класс {propClass} объекта {scheme}."); } }
public void GetPropsTest() { // ARRANGE const string testPropSchemeSid = "test-resource"; var testResourceScheme = new PropScheme { Sid = testPropSchemeSid }; var randomSourceMock = new Mock <IDropResolverRandomSource>(); randomSourceMock.Setup(x => x.RollWeight(It.IsAny <int>())) .Returns(1); randomSourceMock.Setup(x => x.RollResourceCount(It.IsAny <int>(), It.IsAny <int>())) .Returns(1); var randomSource = randomSourceMock.Object; var schemeServiceMock = new Mock <ISchemeService>(); schemeServiceMock.Setup(x => x.GetScheme <PropScheme>(It.Is <string>(sid => sid == testPropSchemeSid))) .Returns(testResourceScheme); var schemeService = schemeServiceMock.Object; var propFactoryMock = new Mock <IPropFactory>(); var propFactory = propFactoryMock.Object; var resolver = new DropResolver(randomSource, schemeService, propFactory); var testDropTableRecord = new DropTableRecordSubScheme(testPropSchemeSid, 1) { MinCount = 1, MaxCount = 1 }; var testDropTable = new DropTableScheme(1, testDropTableRecord); // ACT var factProps = resolver.GetProps(new[] { testDropTable }); // ASSERT factProps.Count().Should().Be(1); factProps[0].Scheme.Should().BeSameAs(testResourceScheme); ((Resource)factProps[0]).Count.Should().Be(1); }
public void DropTablePropContainerTest() { // ARRANGE var nodeMock = new Mock <IMapNode>(); var node = nodeMock.Object; var dropTableRecord = new DropTableRecordSubScheme("test-prop", 1) { MinCount = 1, MaxCount = 1 }; var dropTable = new DropTableScheme(1, dropTableRecord); var testPropScheme = new PropScheme { Sid = "test-prop" }; var dropResolverMock = new Mock <IDropResolver>(); dropResolverMock.Setup(x => x.GetProps(It.IsAny <IEnumerable <DropTableScheme> >())) .Returns(new IProp[] { new Resource(testPropScheme, 1) }); var dropResolver = dropResolverMock.Object; var container = new DropTablePropChest(node, new[] { dropTable }, dropResolver); // ACT var factProps = container.Content.CalcActualItems(); // ASSERT factProps.Count().Should().Be(1); factProps[0].Scheme.Should().BeSameAs(testPropScheme); ((Resource)factProps[0]).Count.Should().Be(1); }