|
Eggnogium posted:Yes, this NuGet package isn't used to build projects at all. It contains (or would contain, haven't built the package yet) an exe that is run after all the projects are built to deploy the combined application, in a post-build step of the TFS build workflow. I suppose my post-build scripts are a similar situation. I have a separate project that houses the post-build logic and scripts, which I ensure (by project dependencies) is always built last and (by deleting the post-build project's build output when running the script) is always built. Importing some of this logic via NuGet would be a logical step for me in this scenario, so if your situation seems similar, I would recommend the "dummy project" approach.
|
# ? Sep 12, 2014 14:01 |
|
|
# ? May 17, 2024 15:00 |
|
chmods please posted:Doesn't log4net include a trace appender already though? It does, but it appears to just use Trace.Write no matter the log level. DiagnosticsTraceAppender just shoves the log message into the correct Diagnostics log level.
|
# ? Sep 12, 2014 15:05 |
|
Since so many people have asked about asynchronous and parallel programming this week I'll plug Concurrency in C# as a great book to go over modern (.NET 4+) concurrency techniques. It's in a cookbook style approach where each chapter has a theme (async/await, TPL, Rx) and a bunch of examples that build on each other. Excellent book.
|
# ? Sep 12, 2014 20:15 |
|
Ithaqua posted:Don't do this from build. Use a real release tool. What would you use for this?
|
# ? Sep 13, 2014 13:02 |
|
I'm unit testing the business logic of a personal project I've been working on for a few months and there's something that's been niggling at me. Be warned that this question is completely unimportant and mundane, but part of the point of doing this project is to help me decide on the 'right' way of doing things and so I'm allowing myself to obsess over minutiae in a way that I wouldn't normally do if I was doing this as part of an actual job. The problem stems from the fact that I'm trying to following a guideline of only having one assert per-unit test, so that each test only checks a single rule. But the reality is that some of the methods have several outcomes if they run successfully, which is leading to an ugly amount of code duplication. For reference the project is a web based clone of the GBA turn-based strategy game Advance Wars. The code below tests various outcomes of the AttackUnit() method when it is run successfully and it should demonstrate my annoyance. C# code:
The only thing that's really causing me to doubt myself here is that the preconditions for all three tests are identical, so any small change in how the application works would require the same changes to be made in three different places instead of one, which immediately sets off alarm bells. But the advantages of doing it as above is that when I run the tests I get a very clear and precise description of all the expected behavior of this method. I realize this is ultimately a fairly trivial decision, but any input is appreciated. I've not had a great deal of experience writing unit tests so it's something I am trying to learn more about. Edit: Also let me know if that code belongs in the coding horrors thread :/ Leyburn fucked around with this message at 13:37 on Sep 13, 2014 |
# ? Sep 13, 2014 13:32 |
|
Leyburn posted:The only thing that's really causing me to doubt myself here is that the preconditions for all three tests are identical, so any small change in how the application works would require the same changes to be made in three different places instead of one, which immediately sets off alarm bells. But the advantages of doing it as above is that when I run the tests I get a very clear and precise description of all the expected behavior of this method. What do we do when we are using identical code in multiple places? Write a function.
|
# ? Sep 13, 2014 14:23 |
|
Yeah that probably is the best thing to do. I was worried about sacrificing the readability of the tests, but you're right, that's probably not going to be a big problem in this case.
|
# ? Sep 13, 2014 14:47 |
|
Leyburn posted:Yeah that probably is the best thing to do. I was worried about sacrificing the readability of the tests, but you're right, that's probably not going to be a big problem in this case. I think your tests are actually going to be far more readable once you encapsulate out all your Arrange logic into a separate PreapareUnitToAttack method or something similar.
|
# ? Sep 13, 2014 14:59 |
|
Yeah. Read up on this: http://blog.8thlight.com/uncle-bob/2013/09/23/Test-first.html I don't agree 100% with everything he says but tests are much more readable once they're refactored into a "given, when, then" structure.
|
# ? Sep 13, 2014 15:18 |
|
Yeah that's exactly the kind of structure I've been aiming for with these tests. I was a bit hesitant to hide the setup section of these tests away in methods because it reduced my ability to see exactly what each test does at a glance, but I guess with properly named methods that shouldn't be an issue. The 'Given' steps of these particular tests are sufficiently complex to justify hiding it away. Very quickly refactoring the tests to encapsulate the common setup code leaves me with something like this: C# code:
|
# ? Sep 13, 2014 17:00 |
|
Leyburn posted:Of course now it is the use of the out parameter to expose the mocked repository that is bothering me, there are other ways around that problem however. I'll need to have a bit of a think about how I want to do it Make two methods. One returns the repo, one returns the service.
|
# ? Sep 13, 2014 17:29 |
|
Adahn the nameless posted:What would you use for this? If you want to stay in the Microsoft stack and keep it simple (and can afford licensing costs), MS Release Management fits the bill. It can kick off a custom workflow-based deployment sequence, a DSC script, or Chef. DSC, Chef, or Puppet are all attractive and reasonable options here.
|
# ? Sep 13, 2014 17:32 |
|
Ithaqua posted:If you want to stay in the Microsoft stack and keep it simple (and can afford licensing costs), MS Release Management fits the bill. It can kick off a custom workflow-based deployment sequence, a DSC script, or Chef.
|
# ? Sep 14, 2014 05:55 |
|
Destroyenator posted:If you're doing web stuff Octopus Deploy is also pretty good. It can handle setting up IIS correctly and doing web config transforms / connection strings etc. Yeah, RM can do config file transforms (in a way) and it has built-in stuff for lots of Windows stuff. SSDT publishing, IIS, service installation, etc. They added Chef and DSC support in the last quarterly update, along with support to publishing directly to Azure IaaS VMs if you care about that. I think Microsoft's end goal is making continuous delivery something that you can set up really easily as long as you're using their products from end to end. Which makes sense. I don't have any Octopus Deploy experience, but it looks solid.
|
# ? Sep 14, 2014 06:58 |
|
I thought it was only assert over one object/mock and sub stub the rest. Not only one assert...
|
# ? Sep 14, 2014 10:33 |
|
Yeah, one assert is really overkill - you will hate yourself once you start to actually maintain these tests. I tend to focus more on "one scenario" - e.g. if I have some billing code, I check that the generated invoice has all its fields filled with the right data in one test case.
|
# ? Sep 14, 2014 12:16 |
|
There's a framework ideal for writing scenario-based BDD-style unit test that ties into MSTest. It's called Given. Each [TestMethod] ideally has one assert, but the givens and whens are reusable across each test method so it's not painful to maintain at all. When you execute your tests the framework prints a textual output for each scenario like: Given x and y and z When something happens, Then a and b and c Where a, b, and c are your [TestMethod]s. It's my favorite way to write tests because you end up with an easily-readable textual summary for each test that explains how the component-under-test is supposed to work. It's tests as code documentation.
|
# ? Sep 14, 2014 14:20 |
|
Ithaqua posted:RM... Green_Machine posted:There's a framework ideal for writing scenario-based BDD-style unit test that ties into MSTest. It's called Given.
|
# ? Sep 14, 2014 15:01 |
|
I'm having a weird issue with a double value drifting in a for loop. I wrote a C# program to control another program and the details don't really matter but after some amount of time my double drifts by ~0.00000000000001 and it is messing with my measurements a little bit. In the most recent case, the loop processed 32 times, incrementing a double starting at 1.95 by 0.05 each time. The 30th value was 3.55 and the 31st value was 3.44999999999999. The code is pretty straightforward and I only change the value in one place so I'm not sure what is going on. code:
|
# ? Sep 14, 2014 20:11 |
|
IratelyBlank posted:I'm having a weird issue with a double value drifting in a for loop. It's not weird. Doubles are not exact. http://stackoverflow.com/questions/1165761/decimal-vs-double-which-one-should-i-use-and-when [edit] Also, this is really ugly: cmbProject.Text = "Iris_" + sp[0] + "_" + sp[1] + "_mm_34_8x_13"; Try cmbProject.Text = string.Format("Iris_{0}_{1}_mm_34_8x_13", sp[0], sp[1]); New Yorp New Yorp fucked around with this message at 20:30 on Sep 14, 2014 |
# ? Sep 14, 2014 20:25 |
|
Ithaqua posted:It's not weird. Doubles are not exact. Ah ha, that was simple. Thanks for the help.
|
# ? Sep 14, 2014 21:03 |
|
IratelyBlank posted:I'm having a weird issue with a double value drifting in a for loop. I wrote a C# program to control another program and the details don't really matter but after some amount of time my double drifts by ~0.00000000000001 and it is messing with my measurements a little bit. Floating point addition and multiplication aren't associative because every computation may result in a loss of precision. Your loop compounds the precision errors from previous loop iterations. You need to rewrite your loop so that size does not depend on the previous iteration. Wrong: C# code:
C# code:
|
# ? Sep 14, 2014 22:13 |
|
Fixing the loop to use an int is certainly the right way to go but you should read up on the difference between float/double and decimal. Basically if you care about being exact (ie storing money) you should be using decimals. http://stackoverflow.com/a/618596
|
# ? Sep 15, 2014 00:56 |
|
why is MEF2 so underdocumented and kind of insane. i'm totally behind the tradeoffs they made like dropping private-import stuff, focusing on startup performance, that's all good and i'd like to move to it - but there's no actual way to find out how to USE stuff like new concrete metadata views. also, it isn't CLS-compliant, and they close all issues saying they're not "targetting" that??
|
# ? Sep 15, 2014 10:12 |
|
Sedro posted:Floating point addition and multiplication aren't associative because every computation may result in a loss of precision. Changing to Decimal would fix this particular problem because Decimal stores a number in such a way that it can be represented in base 10 without loss of precision.
|
# ? Sep 15, 2014 14:48 |
|
Got a hosed up query (sigh) I want to do as close to right as I can in LINQ. As it stands I'm basically doing this: code:
Edit: did some research and realized LINQ lets you match on lists! So I made a function to take some id for a list and spit out said list, and want to do it like so: code:
vvv and I just edited, hah. But yes I am passing in a list from a private function. Fuck them fucked around with this message at 16:17 on Sep 15, 2014 |
# ? Sep 15, 2014 15:01 |
|
gently caress them posted:in LINQ, what's the idiom for saying "where c.category is 1, 2, 13, 20, 21, or 23?" If I'm reading you right: new List<int>{ 1, 2, 13, 20, 21, 23 }.Contains(c.category). Works for LINQ to Entities if you define the list outside the LINQ code.
|
# ? Sep 15, 2014 16:12 |
|
Opulent Ceremony posted:If I'm reading you right: new List<int>{ 1, 2, 13, 20, 21, 23 }.Contains(c.category). Works for LINQ to Entities if you define the list outside the LINQ code. Would items = items.Where(Function(x) x.trTypeID.Equals(CategoryMapper(_company))) work?
|
# ? Sep 15, 2014 16:19 |
|
gently caress them posted:Would items = items.Where(Function(x) x.trTypeID.Equals(CategoryMapper(_company))) work? CategoryMapper is returning the List right? So it doesn't make sense to compare a single int to a List of ints. If you just want to further filter your items so that only those whose trTypeID is within the list returned from CategoryMapper, this should work: items = items.Where(Function(x) CategoryMapper(_company).Contains(x.trTypeID)) Although probably assign the return value of CategoryMapper somewhere beforehand if using that function takes any work, you don't want to execute it for every item in your items list.
|
# ? Sep 15, 2014 16:25 |
|
That worked great, thank you. It's still weird letting LINQ just do it all for me, but it definitely works when it does.
|
# ? Sep 15, 2014 16:48 |
|
gently caress them posted:That worked great, thank you. If you're after optional conditions in the where clause, there's always predicate builder.
|
# ? Sep 16, 2014 02:43 |
|
mortarr posted:If you're after optional conditions in the where clause, there's always predicate builder. I highly recommend this library. I've used it in a few places when dynamically building expression trees and it's always worked as expected.
|
# ? Sep 16, 2014 14:12 |
|
mortarr posted:If you're after optional conditions in the where clause, there's always predicate builder. I don't have any need for this right now, but I have a question about their example code: C# code:
quote:The temporary variable in the loop is required to avoid the outer variable trap, where the same variable is captured for each iteration of the foreach loop. Why would the same variable be captured on each iteration?
|
# ? Sep 16, 2014 15:03 |
|
It's not executed on each iteration, so the reference pointer changes to the last variable to be set as the predicate.(It really hoists the variable outside the loop and you reassign it every iteration). Assigning a variable inside the loop creates a new pointer for each iteration. Closures! Funking Giblet fucked around with this message at 15:10 on Sep 16, 2014 |
# ? Sep 16, 2014 15:07 |
|
GrumpyDoctor posted:I don't have any need for this right now, but I have a question about their example code: That code doesn't make any sense, anyway. Only the result of the last query is returned. It's equivalent (as far as I can tell) to: code:
|
# ? Sep 16, 2014 15:12 |
|
GrumpyDoctor posted:I don't have any need for this right now, but I have a question about their example code: It's not captured on each iteration any longer. We made this change is VS2012. The temporary is no longer needed.
|
# ? Sep 16, 2014 15:24 |
|
ljw1004 posted:It's not captured on each iteration any longer. We made this change is VS2012. The temporary is no longer needed. I assume that's a C# 5 compiler thing, so it doesn't matter which framework version you're using, right?
|
# ? Sep 16, 2014 15:25 |
|
Ithaqua posted:That code doesn't make any sense, anyway. Only the result of the last query is returned. However, incidentally it would've had the behavior you described if the sample hadn't used the temporary variable and you compiled the code on VS2010; you'd still get an AND linked chain of filters, but all filters would search for the last keyword only due to an implementation detail regarding foreach variables in older C# compilers.
|
# ? Sep 16, 2014 16:02 |
|
SirViver posted:No, that's not what it does (assuming IQueryable behaves the same as LINQ to Objects). The loop "appends" the Where() filter for each keyword to the query, so you end up with an AND connection of the keywords. Huh, I didn't realize Linq to objects did that. I'll have to test it out.
|
# ? Sep 16, 2014 16:34 |
|
|
# ? May 17, 2024 15:00 |
|
ljw1004 posted:It's not captured on each iteration any longer. We made this change is VS2012. The temporary is no longer needed. Was the old behavior originally intended, or was it a bug? That behavior seems incredibly counterintuitive to me, especially because, if I understand right, there's no way to explicitly request it anywhere in the language. (Also, how did I not know that?)
|
# ? Sep 16, 2014 16:47 |